⑴ 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]);
}