Input -
COMETQ
HVNGAT
Here's the code -
#include <stdio.h>
#include <stdlib.h>
#define MAXLEN 6
main(void)
{
char comet[MAXLEN], group[MAXLEN];
unsigned long int result[2] = { 1,1 };
short int i, j;
scanf("%s",comet);
scanf("%s",group);
printf("\nComet's Name: %s\nGroup's Name: %s",comet,group);
printf("\nComet's No.: %ld\nGroup's No.: %ld",result[0],result[1]);
i = j = 0;
while(comet[i]!='\0' && i<MAXLEN){
result[0] *= (comet[i] - 'A' + 1);
i++;
}
while(group[j]!='\0' && j<MAXLEN){
result[1] *= (comet[j] - 'A' + 1);
j++;
}
printf("\nComet's No.: %ld\nGroup's No.: %ld",result[0],result[1]);
printf("\nComet's No. Mod 47: %ld\nGroup's No. Mod 47: %ld",result[0]%47,result[1]%47);
if(result[0]%47 == result[1]%47)
printf("\nGO");
else
printf("\nSTAY");
exit(0);
}
Now, as far as I know, scanf() reads a string till a whitespace is detected. But here, the output is-
Comet's Name: COMETQHVNGAT
Group's Name: HVNGAT
Comet's No.: 1
Group's No.: 1
Comet's No.: -534663680
Group's No.: 994500
Comet's No. Mod 47: 43
Group's No. Mod 47: 27
STAY
But, shouldn't it be like this?
comet = "COMETQ" & Group = "HVNGAT"
I don't understand why isn't this happening?
In addition, when the size of comet
is 6 bytes, how can it store - COMETQHVNGAT
?