#include <stdio.h>
#include <stdlib.h>
/*
* Solution Program for FizzBuzz (codeeval.com) - https://www.codeeval.com/open_challenges/1/
*/
int main(int argc,char *argv[])
{
FILE *fp;
int x,y,count,i;
if (argc < 2) {
printf("Error :- File not specified \n");
exit(0);
}
fp = fopen (argv[1],"r");
if (fp == NULL) {
printf("Error :- Can't open file \n");
exit(0);
}
while (fscanf(fp,"%d %d %d",&x,&y,&count) != EOF ) {
printf("Read - X = %d Y = %d Count = %d\n",x,y,count);
if ( x < 1 || x > 20 || y < 1 || y > 20 || count < 21 || count > 100) {
printf("Invalid Input - please use Ranges X[1-20] Y[1-20] Z[21-100]\n");
exit(0);
}
for (i =1; i <= count;i++) {
if(!(i%x) && !(i%y)){
putchar('F');
putchar('B');
} else if (!(i%x)) {
putchar('F');
} else if (!(i%y)) {
putchar('B');
} else {
printf("%d",i);
}
putchar(' ');
}
putchar('\n');
}
return 0;
}
#include <stdlib.h>
/*
* Solution Program for FizzBuzz (codeeval.com) - https://www.codeeval.com/open_challenges/1/
*/
int main(int argc,char *argv[])
{
FILE *fp;
int x,y,count,i;
if (argc < 2) {
printf("Error :- File not specified \n");
exit(0);
}
fp = fopen (argv[1],"r");
if (fp == NULL) {
printf("Error :- Can't open file \n");
exit(0);
}
while (fscanf(fp,"%d %d %d",&x,&y,&count) != EOF ) {
printf("Read - X = %d Y = %d Count = %d\n",x,y,count);
if ( x < 1 || x > 20 || y < 1 || y > 20 || count < 21 || count > 100) {
printf("Invalid Input - please use Ranges X[1-20] Y[1-20] Z[21-100]\n");
exit(0);
}
for (i =1; i <= count;i++) {
if(!(i%x) && !(i%y)){
putchar('F');
putchar('B');
} else if (!(i%x)) {
putchar('F');
} else if (!(i%y)) {
putchar('B');
} else {
printf("%d",i);
}
putchar(' ');
}
putchar('\n');
}
return 0;
}
Comments