arrays - C program skipping over user input? -
i'm making program takes input user of how many numbers want in array , numbers in arrays compare 2 find unions in intersections.
i have written reason after user inputs how many numbers want , numbers first array(a), skips entire user input second array(b).
the computations union , intersection correct(not shown) can't figure out i'm missing. i'm quite new @ c there minor issue i'm missing.
thanks help!
int main(void){ int i, j, x, y; int elema, elemb; int a[10] = {0}; int b[10] = {0}; // prompts user enter amount of numbers in array // asks user enter values (0-9) inputted. printf("enter number of elements in set a: \n"); scanf("%d", &elema); printf("enter %d number(s) set a: \n", elema); scanf("%d", &x); if(x < 10) a[x]=1; // sets index in array 1 if //corresponding number has been inputted // prompts user enter amount of numbers in array // asks user enter values (0-9) inputted. printf("enter number of elements in set b: \n"); scanf("%d", &elemb); printf("enter %d number(s) set b: \n", elemb); scanf("%d", &y); if(y < 10) b[y]=1; // sets index in array 1 if //corresponding number has been inputted *** rest of code ***
here:
printf("enter %d number(s) set a: \n", elema); scanf("%d", &x);
you reading 1 int, others queued, , used when use scanf other time, without user input.
Comments
Post a Comment