I've been looking around the internet and I believe I have found the five most common programmer interview questions.
I want to see your solutions.
- fizzbuzz
- matrix multiplication
- prime factorization
- huffman compression
- fast fourier transform
Also combinatoral explosion
Code:
void FizzBuzz(int x) {
if (x % 3 == 0) // Or (!(x % 3))
printf("Fizz");
if (x % 5 == 0) // Or (!(x % 5))
printf("Buzz");
printf("\n");
return;
}
int main(void) {
for (int x=0;x=x+1;x<=10)
FizzBuzz(x);
return 0;
}
FizzBuzz in C, as close as I remember. My C-fu is weak...
I'm taking it into another function, because grouping, and leaving out most unnecessary syntax, while keeping the returns. If I wanted to make it small, i'd inline it, use the alternative boolean if statement, and abuse argc.
I forget: does C now include constructs like x++; or ++x; ? I know they're in C++...
(04-18-2015, 07:59 AM)Tommyand Wrote: [ -> ]Code:
#include <stdio.h>
void FizzBuzz(int x); //Header of the function
int main(void) {
int x; //cannot declare a variable in the condition of the loop (valid in C++, java but not i C(95 ?)
for (x=1; x<=10 ;x++){
FizzBuzz(x);
}
return 0;
}
void FizzBuzz(int x) { //the function
if (x % 3 == 0){ // Or (!(x % 3))
printf("%d : Fizz\n", x);
}
if (x % 5 == 0){ // Or (!(x % 5))
printf("%d : Buzz\n", x);
}
}
I correct it... It miss a lot of {} (after the if and the for), I show x when fizz or buzz is found and add the stdio library
Great: that indentation XD
my eyes are bleeding.
(04-20-2015, 08:21 AM)GISED_Link Wrote: [ -> ] (04-18-2015, 07:59 AM)Tommyand Wrote: [ -> ]Code:
#include <stdio.h>
void FizzBuzz(int x); //Header of the function
int main(void) {
int x; //cannot declare a variable in the condition of the loop (valid in C++, java but not i C(95 ?)
for (x=1; x<=10 ;x++){
FizzBuzz(x);
}
return 0;
}
void FizzBuzz(int x) { //the function
if (x % 3 == 0){ // Or (!(x % 3))
printf("%d : Fizz\n", x);
}
if (x % 5 == 0){ // Or (!(x % 5))
printf("%d : Buzz\n", x);
}
}
I correct it... It miss a lot of {} (after the if and the for), I show x when fizz or buzz is found and add the stdio library
I specifically left out the brackets because they are unnecessary, because it's a single line of code inside the if / for, and that is allowed in C. I was thinking about that, and it does look nicer without them...
The initialization of the variable inside the for loop? Like I said, weak C-foo. I did C++, not C.
However, switching around the order of the functions made little sense, and you actually messed up the FizzBuzz function. That final printf('/n') is seperate for a reason... So, my suggustion would be to put the number in the final printf statement, along with the newline. So...
Code:
if (blah)
printf("Fizz");
if (blah2)
printf("Buzz");
printf(": %d\n, x);
1,Have an interview coming up?
2,“Tell me about yourself.”
3,“What interests you about this job?”
4,“Why are you thinking about leaving your job?” Or: “Why did you leave your last job?”
5,“Why would you excel at this job?”
6,“What do you know about our company so far?”
7,“Tell me about a time when …”
8,“What would you do in your first 90 days in this position?”
9,“What’s most important to you in a new position?”
10,“What salary range are you looking for?”
[SPAM LINK REMOVED]