⑴ c語言菜鳥問題:C語言里怎麼將要算的數據一次輸入一次輸出
你看下吧,我給你代碼改了下,在vs2005下執行通過了。
#include <stdio.h>
#include <stdlib.h>
main()
{
int r, repeat,s;
float *x; //將x定義成一個指針。
int n;
scanf("%d", &repeat);
x = (float *)malloc(sizeof(float)*repeat);
//得到repeat的值後,對x申請內存空間,x就是一個repeat大小的數組
for(r=0; r<repeat; r++)
{
scanf("%f", &x[r]);//將值一次全部輸入到x數組中
}
for (r=0;r<repeat;r++) //計算,得到你想要的結果
{
n = 0;
s = x[r] * 1000;
if(s%1000>= 1)
n = n + 1;
if(s%100>=1)
n = n + 1;
if(s%10>=1)
n = n + 1;
printf("%d\n", n);
}
}
⑵ c語言 怎麼實現多組數據的同時輸入和輸出
用一個足夠長的數組記錄每輸入3個數之後的計算結果
然後統一列印
⑶ 如何通過C語言,把感測器實時讀出的整型數字封裝成一個數組並統一輸出
這個用假設法就好了,你先假設第一個元素是最大值,然後遍歷數組,比最大值大,就重新賦值即可,示例代碼如下:
#include<stdio.h>#define SIZE 8 int main(){ int number[SIZE]={95,45,15,78,84,51,24,12}; //假設法int max = number[0];for (int inx=0; inx!=SIZE; ++inx){if (number[inx] > max) max = number[inx];else continue;} printf("the max value is:%d\n", max);}
⑷ 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語言如何在判斷n組數據後,在後面統一輸出數據答案
把多組數據存入一個數組A[00],再用另一個數組對應,比如B[100]吧,數組大小看具體情況
然後比如第一個數比特定數大,就讓B[0]=1,如果第一個數比特定數小,就讓B[0]=-1,相等就B[0]=0,等全部數據比較完了,再遍歷B數組,等於1大於,等於0相等,等於-1就小於
⑹ c語言,如何實現多組數據結果對應輸出
可以嘗試用while(scanf("%d%d",&a,&b)==2) 只不過在輸入下一組數據前不要回車,否則就直接輸出了,並且n也失去了意義,如果你實在不嫌煩的話就把a+b的值儲存在數組中然後循環輸出。
int sum[10];
int i=0,j;
while(n--)
{
scanf("%d%d",&a,&b);
sum[i++]=a+b;
}
for(j=0;j<i-1;j++)
printf("%d ",sum[j]);
printf("%d\n",sum[j]);
⑺ C語言中如何實現多組數據輸入輸出
C語言中實現多組數據輸入輸出主要有兩種方式:
1.首先輸入一個n,表示將有n個輸入輸出,例如:
#include<stdio.h>
intmain()
{
intn,a;
scanf("%d",&n);
while(n--){
scanf("%d",&a);
printf("輸出:%d ",a);
}
return0;
}
/*
運行結果:
3
255
輸出:255
156
輸出:156
125
輸出:125
*/
2.使用while(scanf("%d",&n)!=EOF){}語句,直達輸入ctrl+z,結束輸入,例如:
#include<stdio.h>
intmain()
{
inta;
while(scanf("%d",&a)!=EOF){
printf("輸出:%d ",a);
}
return0;
}
/*
運行結果:
54
輸出:54
5156
輸出:5156
21
輸出:21
^Z
*/
⑻ c語言如何輸入多個數據,讓這些數據分別運行統一算式
可以,用循環語句實現,稍等,我用電腦補個代碼
#include<stdio.h>
#defineMAX3000//定義宏MAX=數據最大量
intmain()
{
intday=0,hour,minute,m,i;
printf("Pleaseminute:");
for(i=0;i<MAX;i++)//循環MAX次
{
day=0;hour=0;minute=0;m=0;//初始化數據
scanf("%d",&m);
minute=m%60;
hour=m/60;
while(hour>=24)
{
hour-=24;
day++;
}
if(m==0)break;//無法得到輸入數據時終止循環
printf("%d天%d小時%d分鍾 ",day,hour,minute);
}
}
⑼ C語言如何多組數據輸入輸出
#includeintpow(inta,intn)//計算a的n次方{if(n==1)returna;returna*pow(a,n-1);}intmain(){intT;intn,k,sum,i;scanf("%d",&T);while(T--){sum=0;scanf("%d%d",&n,&k);for(i=1;i
⑽ C語言中循環輸入多個數後,如何把輸入的數全部輸出
首先你選用的數據結構就有問題,想實現這種功能需要使用數組或者指針來完成。通過一個x變數只可以存一個數據,下次再輸入的時候就自動被覆蓋了。
例如int
x[5];
for(i=0;i<5;i++)
{scanf("%d",x[i]);
}
for(i=0;i<5;i++)
{printf("%d",x[i]);
}