Write a program that will take in a single number as a commandline argument (i.e. not using scanf or fscanf) which is formed as a decription seed to the rules below. The rules below, when followed correctly give you a 4 letter string you should know for the rest of your degree.
Letter 1 is the difference between 10 times the seed, and the remainder when the seed is divided by 5.
Letter 2 is the fourth letter minus half the seed value.
Letter 3 is letter 2 minus a quarter of the seed.
Letter 4 is eleven times the seed.
Print this as a single word out to command line.
Solution:
int main(int c,char *v[])
{
if(c!=2)
{
printf("Usage: %s < number > \n",*v);
return 0;
}
int seed=atoi(v[1]);
char A=10*seed-seed%5,
B=11*seed-seed/2,
C=B-seed/4,
D=11*s;
printf("%c%c%c%c\n",A,B,C,D);
return 0;
}
Letter 1 is the difference between 10 times the seed, and the remainder when the seed is divided by 5.
Letter 2 is the fourth letter minus half the seed value.
Letter 3 is letter 2 minus a quarter of the seed.
Letter 4 is eleven times the seed.
Print this as a single word out to command line.
Solution:
int main(int c,char *v[])
{
if(c!=2)
{
printf("Usage: %s < number > \n",*v);
return 0;
}
int seed=atoi(v[1]);
char A=10*seed-seed%5,
B=11*seed-seed/2,
C=B-seed/4,
D=11*s;
printf("%c%c%c%c\n",A,B,C,D);
return 0;
}
No comments