Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Why can you use SCANF to send multiple data to array a[i], where n is a plastic variable, so only one data can be stored.
Why can you use SCANF to send multiple data to array a[i], where n is a plastic variable, so only one data can be stored.
scanf("%d ",& ampn);

And (n! =0)

{

a[I]= n;

I = i++;

scanf("%d ",& ampn);

}

Enter an integer first, that is, the variable n.

As long as n is not equal to 0.

Enter the cycle

Assign the value of n to the elements in array A, the array subscript starts from 0, and I should be initialized to 0 instead of 1.

I = i++; Equivalent to i = i;; i++; There is no need to just i++;+; +;

Then scanf ("%d ",&; n); Re-enter the value of n as long as n is not equal to 0.

The loop will continue to assign values to the elements of array a.

The size of array A is 50, and the values in the first 50 must have 0, otherwise it will overflow.

# include & ltstdio.h & gt

# include & ltstdlib.h & gt

Master ()

{

int i=0,n,m;

int a[50];

Printf ("Please insert data ending in 0 \ n");

scanf("%d ",& ampn);

And (n! =0)

{

a[I]= n;

i++;

scanf("%d ",& ampn);

}

for(m = 0; M< me; m++)

{

printf("%d\n ",a[m]);

}

}