当前位置:首页 » 编程语言 » c语言连续输入输出
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言连续输入输出

发布时间: 2022-01-15 04:22:32

㈠ 跪求c语言如何多次输入输出

这样处理:
while(1)
{
scanf("%d", &a);// 先读a
if(a==-1) break; // 如果为-1就退出
scanf("%d%d", &b, &c); // 没有退出,说明输入不是-1,接着读取b和c
// 处理a,b,c
}

㈡ C语言中如何实现多组数据输入输出

仔细认真看看下面的会对你有帮助的,嘿嘿

输入格式:有多个case输入,直到文件结束
输出格式:一行一个结果
Problem Description
Your task is to Calculate a + b.
Too easy?! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.

Input
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input
1 5
10 20

Sample Output
6
30

Author
lcy

Recommend
JGShining

#include <stdio.h>

int main()
{
int a,b;
while( scanf( "%d%d" , &a , &b ) != EOF ) //输入直到文件结尾
{
printf( "%d\n" , a+b ); //一行一个结果
}
return 0;
}

HDOJ1090
输入格式:先输入有case数,再依次输入每个case
输出格式:一行一个结果
#include <stdio.h>
Problem Description
Your task is to Calculate a + b.

Input
Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.

Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input
2
1 5
10 20

Sample Output
6
30

Author
lcy

Recommend
JGShining

int main()
{ int n,a,b;
scanf( "%d" , &n ); //输入的case数
while( n-- ) //控制输入
{ scanf( "%d%d" , &a , &b );
printf( "%d\n" , a+b ); //一行一个结果
}
return 0;
}

HDOJ1091
输入格式:每行输入一组case,当case中的数据满足某种情况时退出
输出格式:一行一个结果
Problem Description
Your task is to Calculate a + b.

Input
Input contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.

Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input
1 5
10 20
0 0

Sample Output
6
30

Author
lcy

Recommend
JGShining

#include <stdio.h>

int main()
{
int a,b;
while( scanf( "%d%d" , &a , &b ) && (a||b) ) //输入直到满足a和b均为0结束
{
printf( "%d\n" , a+b ); //一行一个结果
}
return 0;
}

HDOJ1092
输入格式:每组case前有一个控制输入个数的数,当这个数为0结束
输出格式:一行一个结果
#include <stdio.h>
Problem Description
Your task is to Calculate the sum of some integers.

Input
Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.

Output
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.

Sample Input
4 1 2 3 4
5 1 2 3 4 5
0

Sample Output
10
15

Author
lcy

Recommend
JGShining

int main()
{
int n,sum;
while( scanf( "%d" , &n ) && n ) //每组case前有一个控制该组输入数据的数,为0结束
{
int x;
sum = 0;
while( n-- ) //控制该组输入个数
{
scanf( "%d" , &x );
sum += x;
}
printf( "%d\n" , sum ); //一行一个结果
}
return 0;
}

HDOJ1093
输入格式:一开始有一个控制总的输入case的数,而每个case中又有一个控制该组输入数据的数
输出格式:一行一个结果
Problem Description
Your task is to calculate the sum of some integers.

Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

Output
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.

Sample Input
2
4 1 2 3 4
5 1 2 3 4 5

Sample Output
10
15

Author
lcy
5
#include <stdio.h>
int main()
{
int casnum,n,sum;
scanf( "%d" , &casnum ); //控制总的输入case的数
while( casnum-- ) //控制总的输入个数
{
int x;
sum = 0;
scanf( "%d" , &n ); //每个case中控制该组输入个数
while( n-- )
{
scanf( "%d" , &x );
sum += x;
}
printf( "%d\n" , sum ); //一行一个结果
}
return 0;
}

HDOJ1094
输入格式:总的case是输到文件结尾,每个case中的一开始要输入一个控制该组个数的数
输出格式:一行一个结果
Problem Description
Your task is to calculate the sum of some integers.

Input
Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.

Output
For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.

Sample Input
4 1 2 3 4
5 1 2 3 4 5

Sample Output
10
15

6

#include <stdio.h>
int main()
{
int n,sum;
while( scanf( "%d" , &n ) != EOF ) //输出到文件结尾
{
int x;
sum = 0;
while( n-- ) //控制该组输入个数
{
scanf( "%d" , &x );
sum += x;
}
printf( "%d\n" , sum ); //一行一个结果
}
return 0;
}

HDOJ1095
输入格式:输入直到文件结束
输出格式:一行一个结果,结果输完后还有一个blank line
Problem Description
Your task is to Calculate a + b.

Input
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output
For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.

Sample Input
1 5
10 20

Sample Output
6

30
7
#include <stdio.h>
int main()
{
int a,b;
while( scanf( "%d%d" , &a , &b ) != EOF ) //输入直到文件结束
{
printf( "%d\n\n" , a+b ); //一行一个结果,结果输完后还有一个回车
}
return 0;
}

HDOJ1096
输入格式:一开始输入总的case数,每组case一开始有控制该组输入个数的数
输出格式:一行一个结果,两个结果之间有一个回车,注意最后一个case的处理。
Problem Description
Your task is to calculate the sum of some integers.

Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

Output
For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.

Sample Input
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3

Sample Output
10

15

6

#include <stdio.h>

int main()
{
int casnum,n,sum;
scanf( "%d" , &casnum ); //总的输入case数

while( casnum-- ) //控制输入组数
{
int x;
sum = 0;
scanf( "%d" , &n ); //控制每组的输入个数
while( n-- )
{
scanf( "%d" , &x );
sum += x;
}
printf( "%d\n" , sum ); //一行一个结果
if( casnum ) printf( "\n" ); //两两结果之间有一个回车,最后一个结果后面没有
}
return 0;
}

㈢ C语言怎样连续输入多行数据,然后将每行对应结果输出急求😘

用{} 来表示,每个代码后加个大框就可以了,然后中间用 else隔开

㈣ c语言中,一次连续输入多组数据,并且最后连续输出多组结果,应该用哪种方法

用二维数组就可以实现一次连续输入多组数据。思路是嵌套循环,外层循环控制二维数组的行数(也就是第几组数据),内层循环控制这组数据中数据个数。
采用二维数组方法的有点在于,这种随机存取的数据结构方便查找和检索,但一定要注意这种方法不便于向已有数据中插入和删除数据。

㈤ C语言用for如何实现多次循环的输入输出

#include<stdio.h>
void
main()
{
int
year;
printf("请输入年份\n");
scanf("%d",&year);
if(year%4==0)
printf("%d
是闰年",year);
else
printf("%d
不是闰年",year);
getch();
}

这个程序是错误的、你用的编译器是WIN-tc把!
判断是否是闰年的判断的条件应该是if((year%4==0&&year%100!=0)||(year%400==0))

㈥ C语言:如何实现连续多行输入,然后再多行输出如图

输入放在while循环中,当条件满足就退出循环即可

㈦ C语言中scanf函数的使用输入double型的使用方法,如何连续输入并且用printf连续输出我这个怎么错了

在输入数据的时候用空格隔开两个数据,不要用逗号,如果要用逗号,请在格式符中用逗号,即改成scanf("%lf,%lf",&a,&b);

㈧ c语言如何多次输入 然后一次性输出

  1. 用循环语句多次读入。 最后再输出即可。

  2. 例如:

    inta[100],i;
    for(i=0;i<100;i++)scanf("%d",a+i);//循环多次输入
    for(i=0;i<100;i++)printf("%d",a[i]);//一次性输出

㈨ C语言中如何让连续输入和输出在一排内完成

不知道楼主想干嘛···
如果楼主是希望输入字符时,希望把空格忽略掉,只要调用scanf时,在%号前加上个空格即可。如:
#include
int
main()
{
char
c;
scanf("
%c",&c);
putchar(c);
}
这样,即使你输入:
d
它也会输出d;
如果不是你想要的答案,还望楼主说清楚你想要的程序功能,然后帮你看看···

㈩ c语言中怎么连续输入几个字符串

1、首先我们新建一个dev C++的项目。