㈠ 跪求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語言如何多次輸入 然後一次性輸出
用循環語句多次讀入。 最後再輸出即可。
例如:
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++的項目。