编程:从键盘输入两个整数,按降序输出这两个数.

作者&投稿:帅蓉 (若有异议请与网页底部的电邮联系)
编写一个程序,从键盘输入两个整数,输出这两个数之和~

这才是正确的程序:
#include
void main()
{
int a,b,sum;
printf("请输入两个整数
");
scanf("%d %d",&a,&b);
sum=a+b;
printf("the sum is:%d
",sum);
}
主函数一般是没有返回值的,应该用void;变量应该先定义,后使用,所以int a,b,sum;要放在
scanf("%d %d"&a,&b);的前面; Scanf那句引号后有个逗号; 输出sum的那一句,冒号:后面应该加个%d ;
还有就是,你main错写成mian了。

代码1.
// 输入3个数,要求按从小到大顺序输出 #include int main() { int a,b,c,t; printf("请输入三个数:"); scanf("%d%d%d",&a,&b,&c); if(a > b) { t = a; a = b; b = t; } if(a > c) { t = a; a = c; c = t; } if(b > c) { t = b; b = c; c = t; } printf("从小到大的顺序是:%d %d %d
",a,b,c); return 0; }代码2.
输入3个字符串,按从小到大顺序输出。 //先用程序对三个数进行从小到大排序,然后修改程序#include#includeint main(){void swap(char *pt1,char *pt2); char a[20],b[20],c[20]; char *p1,*p2,*p3; printf("请输入三个字符串:"); gets(a); gets(b); gets(c); //或用scanf("%s,%s,%s",a,b,c); p1=&a[0];p2=&b[0];p3=&c[0];//三个指针分别指向三个字符数组 if(strcmp(*p1,*p2)>0)swap(p1,p2);//if(strcmp(a,b)>0)swap(a,b); //比较两个字符串的大小,为什么用前一句的时候会出现警告呢 if(strcmp(a,c)>0)swap(a,c);//if(strcmp(*p1,*p3)>0)swap(*p1,*p3); if(strcmp(b,c)>0)swap(b,c);// if(strcmp(*p2,*p3)>0)swap(*p2,*p3); printf("由小到大排列:%s
%s
%s
",a,b,c); return 0;}void swap(char *pt1,char *pt2){ char t[20]; strcpy(t,pt1); strcpy(pt1,pt2); strcpy(pt2,t);//t=*pt1;*pt1=*pt2;*pt2=t;}代码3.
#include #include #define SIZE 3 #define LEN 50 int main(void) { char str[SIZE][LEN]; char (*pst)[LEN]=str; char temp[LEN]; int i,j; printf("Please enter 3 string.
"); for(i=0;i<SIZE;i++) { fgets(*(pst+i),LEN,stdin); } printf("Befor sort:
"); for(i=0;i<SIZE;i++) { fputs(*(pst+i),stdout); } for(i=0;i<SIZE-1;i++) for(j=i+1;j<SIZE;j++) { if(strcmp(*(pst+i),*(pst+j)) == 1) { strcpy(temp,*(pst+i)); strcpy(*(pst+i),*(pst+j)); strcpy(*(pst+j),temp); } } printf("After sort:
"); for(i=0;i<SIZE;i++) { fputs(*(pst+i),stdout); } }

int a,b;
scanf("%d %d",&a,&b);
if ( a>b ) printf("%d %d\n",a,b);
else printf("%d %d\n",b,a);

C++
#include <iostream>
using namspace std;

int main()
{
int a,b;
cin>>a>>b;
if(a>b)
cout<<b<<" "<<a<<endl;
else
cout<<a<<" "<<b<<endl;
return 0;
}

void exchange(int *a, int *b)
{
int tmp;
tmp=*a;
*a=*b;
*b=tmp;
}
void main()
{
int a,b;
cin>>a>>b;
if(a>b)
exchange(&a,&b);
cout<<a<<endl<<b<<endl;
}


C语言 从键盘上输入2个int型数 比较大小,并且显示最小数
- `int main()` 是主函数,程序从这里开始执行;- `int num1, num2, min;` 声明三个整型变量;- `printf("请输入两个整数:\\n");` 显示提示信息;- `scanf("%!d(MISSING) %!d(MISSING)", &num1, &num2);` 从键盘上读取两个整数,并将它们存储在变量 `num1` 和 `num2` 中;...

用C语言编写程序,从键盘输入两个八进制数,计算两数之和并分别用十进制...
include "stdio.h"void main(){ int a,b;printf("请输入2个八进制数:");scanf("%o %o",&a,&b);printf("a+b = %d(十进制)\\n",a+b);printf("a+b = %x(十六进制)\\n",a+b);}

C语言编程题目
下面是一些C编程题目:1. 编写程序,从键盘输入两个整数,输出它们的和、差、积、商、余数。2. 编写程序,从键盘输入三角形的三条边长,判断它们是否可以构成三角形,并输出三角形的类型(等边、等腰、一般)。3. 编写程序,从键盘输入字符串,统计其中的大写字母、小写字母、数字和其他字符的个数,并...

C语言程式 从键盘输入两个小数,输出它们的和及乘积
printf("%f * %f = %f\\n", i, j, i * j);return;} 从键盘输入3个正整数,求他们的乘积并输出来的c语言程式 include "stdio.h"int main(void){ long a,b,c,result; printf("输入三个数:"); scanf("%ld%ld%ld",&a,&b,&c); result=a*b*c; printf("三数之积...

编写一个C程序,功能是:从键盘输入两个字符串str1 str2,并将字符串 str...
由于C的字符串是由字符数组操作的,所以这种题得保证字符数组str1能放得下它自身和拷贝在它后面的str2的内容。不用库函数的话可以如下操作:include "stdio.h"int main(int argc,char *argv[]){char str1[301],str2[101];int i,j;printf("Please enter 2 strings...\\n");scanf("%200s%...

C语言编程:从键盘输入两个实数后,屏幕显示菜单如下内容?
int main(void){     double n1, n2, result;    int choice;    printf("请输入两个实数:");    scanf("%lf%lf", &n1, &n2); ...

c语言 从键盘输入两个整数,求这两个整数的最小值.??
在 C 语言中,可以通过以下代码实现从键盘输入两个整数,然后求这两个整数的最小值:include <stdio.h> int main() { int num1, num2, min;printf("请输入两个整数:\\n");scanf("%d %d", &num1, &num2);if (num1 < num2) { min = num1;} else { min = num2;} printf("最...

C语言程序从键盘上输入两个字符串若不相等将短的字符串连接到长的字符...
include "string.h"define MAX 500 void main(){ char str1[MAX], str2[MAX];int len1, len2;printf("input string 1 : ");gets(str1); \/* 输入字符串1 *\/ printf("input string 2 : ");gets(str2); \/* 输入字符串2 *\/ len1 = strlen(str1); \/* 获取字符串1的长度 *\/ ...

C语言 输入两个整数,求出它们的商和余数
void main(){ int m,n;scanf("%d%d",&m,&n);int q=m\/n;int r=m-q*n;printf("%d %d",q,r);}

编程:从键盘输入两个整数,按降序输出这两个数.
int a,b;scanf("%d %d",&a,&b);if ( a>b ) printf("%d %d\\n",a,b);else printf("%d %d\\n",b,a);

相城区18911662265: 计算机写程序:从键盘上输入任意两个整数、按由大到小的顺序输出 -
喻凡维柳: C# //读入两个参数 ConsoleKeyInfo a = Console.ReadKey(); ConsoleKeyInfo b = Console.ReadKey(); //如果a的值大于b,输出ab,否则输出ba if(a.Key>=b.Key) { Console.WriteLine(a.Key.toString()+","+b.Key.toString()); }else{ Console....

相城区18911662265: C语言程序从键盘任意输入两个整数,按照其从小到大的顺序输出 -
喻凡维柳: #include <iostream> using namespace std; int main(){ int a,b; cin<<a<<b; if(a>b) cout>>a>>">">>b>>endl; else cout>>b>>">">>a>>endl; return 0; }

相城区18911662265: 通过键盘随机输入2个整数,并按从小到大的顺序输出. 编程题 -
喻凡维柳: #include <stdio.h> void main() { int a,b; scanf("%d %d",&a,&b); if(a>b)printf("%d%d"b,a); elseprintf("%d%d"a,b); }

相城区18911662265: c语言 任意输入的 两个整数,按照由小到大的顺序排列后输出 -
喻凡维柳: #include "stdio.h"main(){ int a,b,c,t; scanf("%d%d%d", if (a>b) {t=a;a=b;b=t;} /*交换a,b的值*/ if(...

相城区18911662265: 从键盘输入一个整型数,把这个整型数个位数按降序输出的编程 -
喻凡维柳: #include <iostream>#include <algorithm>#include <string> using namespace std; bool cmp(int a,int b) { return a>b; } int main() { string a; cin>>a; sort(a.begin(),a.end(),cmp); cout<<a; return 0; }/*在VC.6.0下运行*/

相城区18911662265: 关于C语言进行降序排列 -
喻凡维柳: #include "stdio.h" void sort(int *p) {int i,j,k;for (i=0;i<9;i++)for (j=i+1;j<10;j++)if (p[i]<p[j]) {k=p[i];p[i]=p[j];p[j]=k;} }main() {int a[10],i;for (i=0;i<10;i++)scanf("%d",&a[i]);sort(a); }

相城区18911662265: 输入任意个整数,降序排列,用C语言编程解决
喻凡维柳:懒了,最近习惯用库函数了,下面例子用的是C语言标准库函数中的qsort函数,即快排函数 #include <stdio.h> #include <stdlib.h> int comp(const void *a, const void *b )//比较函数 { return *(int*)b - *(int*)a; } int main() { int *pData=NULL;//指向要...

相城区18911662265: C语言编程,选择排序,输入n个整数,对其进行降序排序,n由键盘输入 -
喻凡维柳: #include void main() { int *a, i,j,n; scanf("%d",&n); a = (int*)malloc(sizeof(int)); for(i = 0; i{ int t; scanf("%d",&t); for(j = i-1; j>=0; j ++) if(t else a[j+1] = a[j]; a[j+1] = t; } for(i = 0; iprintf("%d ",a[i]); }

相城区18911662265: vf编程从键盘输入两个数,然后按从小到大的顺序输出. -
喻凡维柳: clear set talk off input "请输入两个数:" to x1 input "请输入两个数:" to x2 if x1<x2?x1,x2 else?x2,x1 endif

相城区18911662265: 急!!!C语言作业答案!!!请高手帮忙!!! -
喻凡维柳: 本人觉得简单易懂的程序才是好的:1.2编写一个程序,从键盘输入两个整数,输出这两个数之和.main() {int a,b,sum=0;clrscr();printf("please a,b:");scanf("%d%d",&a,&b);sum=a+b;printf("sum=%d",sum); }1.5编写一个求a+|b|的...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网