A set of input data is stored into a variable length array

Inputting a set of variable length data is stored to the array, and output.

Available Code:

#include<stdio.h>
int main()                   //输入一组不定长数据存到数组中,并输出。
{
	int a[101],n=0;
	while(1)
	{
		scanf("%d",&a[n++]);
		if(getchar()=='\n')
			break;
	}
	for(int i=0;i<n;i++)
		printf("%d ",a[i]);
	return 0;
} 

Unavailable codes (both of two input data are stored to two arrays, the modifications from the above code):

#include<stdio.h>
int main()                   //输入数据俩俩分别存到两的数组中,并输出。
{
	int a[101],n=0,b[101];
	while(1)
	{
		scanf("%d %d",&a[n++],&b[n++]);
		if(getchar()=='\n')
			break;
	}
	for(int i=0;i<n;i++)
		printf(" %d %d \n",a[i],b[i]);
	return 0;
} 

The second paragraph of code runs (gcc) Results:
Here Insert Picture Description

Why not ask the second paragraph of the code Gangster answer ah ...

Released six original articles · won praise 0 · Views 65

Guess you like

Origin blog.csdn.net/weixin_44562957/article/details/104055697