‘壹’ 怎么用c语言通过两个变量一次输出两组和的值
1.用for循环
for(int i=1;i《=2;++i)
{scanf(。。。。)
printf(“%d”,a+b);
}
2.利用scanf的返回值进行不知道几组的相加
while(scnaf(。。)!=EOF)
printf(“%d
”,a+b);
‘贰’ 急!!!C语言:输出两组数组中相同的数字
//示例代码如下
#include<stdio.h>
#include<stdlib.h>
intmain()
{
intm,n,i,j,flag=0;
int*pm,*pn;
scanf("%d%d",&n,&m);
pm=(int*)malloc(sizeof(int)*m);
pn=(int*)malloc(sizeof(int)*n);
for(i=0;i<m;i++)
scanf("%d",pm+i);
for(i=0;i<n;i++)
scanf("%d",pn+i);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
if(pm[i]==pn[j]){
printf("%d",pn[j]);
flag=1;
}
}
if(!flag)
printf("NO ");
printf(" ");
free(pm);
free(pn);
return0;
}
//示例运行结果
F:c_work>a.exe
57
5917123698
789161792698
917698
‘叁’ 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语言 输入两组数,一组数内可能有重复的数,输出两组数交集,求大神帮我看看该怎么改
有办法,首先,先把两个数组从小到大排序,然后用两个指针分别指向两个数组。然后,对两个数组分别重头进行比较,然后再申请第三个数组,如果说第一个数组较小,则赋值给第三个,分别遍历两个数组,相等的情况就只取一个,就可以了,简单的数据结构。
‘伍’ 在C语言里,printf怎么输出2个变量
%d是整数的输出标识符。要输出两个变量,用逗号隔开即可。标识符和变量的顺序是相对应的,不能错。输出2个变量的代码修改:
{int a,b,c,sum,sum1;
a=10;
b=20;
c=30;
sum=a+b;
sum1=a+b+c;
printf ("sum=%d/nsum1=%d/n",sum,sum1);}
(5)c语言输出两组数据怎么处理扩展阅读:
变量可以通过变量名访问。在指令式语言中,变量通常是可变的;但在纯函数式语言(如Haskell)中,变量可能是不可变(immutable)的。
在一些语言中,变量可能被明确为是能表示可变状态、具有存储空间的抽象(如在Java和Visual Basic中);但另外一些语言可能使用其它概念(如C的对象)来指称这种抽象,而不严格地定义“变量”的准确外延。
如果按存储占用空间来分,变量可以是整型变量,字符型变量,浮点型变量等。当然还有数组,结构体变量等。
变量的命名规则:
变量名必须以字母或下划线 "_" 开头。
变量名只能包含字母数字字符以及下划线。
变量名不能包含空格。如果变量名由多个单词组成,那么应该使用下划线进行分隔(比如 $my_string),或者以大写字母开头(比如 $myString)。
‘陆’ C语言中如何实现多组数据输入输出
C语言中实现多组数据输入输出主要有两种方式:
1.首先输入一个n,表示将有n个输入输出,例如:
#include <stdio.h>
int main()
{
int n,a;
scanf("%d",&n);
while(n--){
scanf("%d",&a);
printf("输出:%d\n",a);
}
return 0;
}
/*
运行结果:
3
255
输出:255
156
输出:156
125
输出:125
*/2.使用while(scanf("%d",&n)!=EOF){}语句,直达输入ctrl+z,结束输入,例如:
#include <stdio.h>
int main()
{
int a;
while(scanf("%d",&a)!=EOF){
printf("输出:%d\n",a);
}
return 0;
}
/*
运行结果:
54
输出:54
5156
输出:5156
21
输出:21
^Z
*/
‘柒’ C语言:以下程序是输出26个大写字母和它们的ASCII代码,每行输出两组数据
26个字母,从0到25,正好26个,如果是《=,就是27个了,i只是个循环控制变量,控制循环的次数而已。
printf("c=%c ascii=%d",ch,ch) ,两个都是ch,因为输出的是同一个变量,只是两个格式显示而已,一个是字符类型%c,一个是整型%d。
‘捌’ C语言中如何实现输入输出多组数据,该如何结束输入
c语言中实现多组数据输入输出主要有两种方式:
1.首先输入一个n,表示将有n个输入输出,例如:
#include
int main()
{
int n,a;
scanf("%d",&n);
while(n--){
scanf("%d",&a);
printf("输出:%d\n",a);
}
return 0;
}
/*
运行结果:
3
255
输出:255
156
输出:156
125
输出:125
*/2.使用while(scanf("%d",&n)!=eof){}语句,直达输入ctrl+z,结束输入,例如:
#include
int main()
{
int a;
while(scanf("%d",&a)!=eof){
printf("输出:%d\n",a);
}
return 0;
}
/*
运行结果:
54
输出:54
5156
输出:5156
21
输出:21
^z
*/