c语言程序:输入两个整型数,然后按其大小的顺序输出这两个数。

作者&投稿:颜元 (若有异议请与网页底部的电邮联系)
C语言编程题,从键盘输入任意3个数,按从小到大的顺序输出~

代码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); } }

#include
int main()
{
int t,a,b,c;
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;
}

/*c语言程序:输入两个整型数,然后按其大小的顺序输出这两个数。*/
include "stdio.h"
void main()
{
int a,b;
printf("请输入a、b二个整数");
scanf("%d,%d",&a,&b);
if(a>b)
{
printf("%d,%d",a,b);
}
else
{
printf("%d,%d",b,a);
}
希望对你有所帮助。

#include<stdio.h>main(){ int a,b; printf("input a b:") scanf("%d%d",&a,&b); if(a<b) printf("%d,%d\n",b,a); else printf("%d,%d\n",a,b);}

#include<stdio.h>int main(){ int a,b; scanf("%d",&a); scanf("%d",&b); if(a<b) { a ^= b; b ^= a; a ^= b; } printf("%d>%d",a,b);}


编写一个C语言程序,输入两个数的乘积和和,输出这两个数。
思路:使用for循环,用减法得到两个数之后,验证乘法是否符合要求,符合则输出,不符合则跳过该循环。程序源码及运行结果如下所示(程序排版系统会自动去掉句首空格,结构混乱请见谅):include<stdio.h> int main(){ int sum,product;printf("请输入两数之和:");scanf("%d",&sum);printf("请输入...

用c语言编写程序:输入两个复数,计算并输出它们的和及乘积
输入两个复数,计算并输出它们的和及乘积c语言编写:include<stdio.h> include<math.h> void main(){ int i1,i2,j1,j2;int sum(int i1,int i2,int j1,int j2);int mul(int i1,int i2,int j1,int j2);printf("请输入第一个复数的实部和虚部:");scanf("%d %d",&i1,&i2)...

编写一个C#程序,实现从键盘中输入两个数字,屏幕输出这两个数值的和...
C#程序源码:static void Main(string[] args){ Console.Write("a=");string a = Console.ReadLine();Console.Write("b=");string b = Console.ReadLine();double x = Convert.ToDouble(a);double y = Convert.ToDouble(b);Console.WriteLine("a+b=" + (x + y));Console.WriteLine("a...

求一个c语言程序,要求输入两个字符串,可以显示出第二个字符串在第一个...
include<stdio.h> include<stdlib.h> int main(){ char str1[50],str2[50];int locat[50];char *p,*q;int i=0,len=0,lct=1,j;printf("请输入字符串1\\n");gets(str1);printf("请输入字符串2\\n");gets(str2);q=str2;for(;*q!='\\0';q++){ len=len+1;} p=str1;q=...

C语言程序设计,“输入两S写字母,将第一个字母转换为小写输出,并输出小 ...
include<stdio.h> void main(){ char c[2];printf("请输入两个字符\\n");scanf("%c%c",&c[0],&c[1]); \/\/输入两个字符时,中间没有空格或回车隔开(直接输入SS即可)\/\/ printf("第一个字符转化结果是:\\n");printf("%c %d\\n",c[0]+32,c[0]+32);printf("第二个字符转化...

编一C语言程序。通过键盘输入2个浮点型数,输出其中的最大值
main(){ float a,b;printf("enter two number:\\n"); \/\/输入两个数 scanf("%f %f",&a,&b); \/\/把输入两个数分别赋给a b if(a>b) printf("%.0f",a); \/\/判断谁大就输出谁 else printf("%.0f",b); \/\/.0是想要小数点后不输出 } ...

c语言程序实现:我想用键盘输入两个数,然后将他们相加再打印出来。我写...
int main(void){ int i,k,sum; \/\/i,k,sum都未赋除值,所以都为随机值 sum = i+k; \/\/此时sum的值为具有随机值的i和k的和,所以放在此处不对,应放在scanf语句后面。scanf("%d,%d\\n", &i, &k); \/\/此处输入应特别注意要和引号中的格式相同,例如:1,2\\n,忘掉\\n就没有...

大一C语言作业:“编写程序输入两个整数,输出它们的商和余数?”应该怎么...
include<stdio.h> int main(){ int a,b,c,d=0;scanf("%d %d",&a,&b);c=a\/b;d=a%b;printf("商是:%d\\n",c);printf("余数是:%d\\n",d);return 0;} 运行可用,输入用空格分分开两个数 比如输入:5 3后回车 输出:商是:1 余数是:2 C 语言属于易学难精的一门计算机语言。

1. 用C语言写一段程序:从键盘上输入两数,判断其大小关系,将判断结果显 ...
1.include <stdio.h> include <string.h> int main(void){ int nNum1,nNum2;printf("请输入第一个整数:");scanf("%d",&nNum1);printf("\\n请输入第二个整数:\\n");scanf("%d",&nNum2);printf("\\n输入的两个数为:%d,%d,其大小关系为:",nNum1,nNum2)if(nNum1 < nNum2)...

求教,编写一个程序,输入两个数,若这两个数异号,求其和,否则若第_百度...
include int main(){ float a,b,c;printf("请输入第一个数:");scanf("%d",a);printf("请输入第一个数:");scanf("%d",b);if(a*b<0)c=a+b;else if(a>b)c=a-b;printf("%f",c);return 0;}

汉中市17883686953: c语言程序:输入两个整型数,然后按其大小的顺序输出这两个数. -
良满田七: #include<stdio.h> main() {int a,b;printf("input a b:")scanf("%d%d",&a,&b);if(a<b)printf("%d,%d\n",b,a);elseprintf("%d,%d\n",a,b); }

汉中市17883686953: C语言,按顺序输出两个数的问题 -
良满田七: #include<stdio.h> void main() {int a,b,t; scanf("d%,d%",&a,&b); if(a<b){ t=a;a=b;b=t;}printf("比较后:a,b的值分别为:a=d%,b=d%\n",a,b); 解析:if(a<b){ t=a;a=b;b=t;}//这个是关键代码,首先是判断a是否小于b,如果 小于的...

汉中市17883686953: 两个值比较大小,c语言运行时如何输入两个数字 -
良满田七: 1、思路:定义两个变量,键盘输入,if判断并输出. 2、参考代码: #include #include int main(){int a,b;scanf("%d%d",&a,&b);if(a>b) printf("最大数是:%d",a);elseprintf("最大数是:%d",b);return 0;}/*运行结果:5 6最大数是:6*/ 1)...

汉中市17883686953: c语言 输入a和b两个整数,按先小后大的顺序输出a和b(交换指针) -
良满田七: 1、新建一个工程和.c文件 ,输入头文件和主函数. 2、然后开始定义变量类型. 3、输入a和b两个整数. 4、对a和b两个不同的整数进行赋值. 5、然后通过if语句实现值大小的比较. 6、输出最后的结果. 7、编译、运行,可以看见按先小后大的顺序输出a和b.

汉中市17883686953: 输入两个整数,进行加减乘除四则运算的c语言程序怎么写啊,拜托了~ -
良满田七: 代码 #include<stdio.h> int main() { int a,b; scanf("%d %d",&a,&b); printf("%d\t",a + b); printf("%d\t",a - b); printf("%d\t",a * b); printf("%d\t",a / b);return 0;} 运行截图分析 C语言中的加减乘除和数学中的加减乘除一样,不同在于符...

汉中市17883686953: c语言 任意输入的 两个整数,按照由小到大的顺序排列后输出 -
良满田七: #include "stdio.h" main() {int a,b,c,t;scanf("%d%d%d",&a,&b,&c);if (a>b){t=a;a=b;b=t;} /*交换a,b的值*/if(a>c){t=c;c=a;a=t;} /*交换a,c的值*/if(b>c){t=b;b=c;c=t;} /*交换c,b的值*/printf("small to big: %d %d %d\n",a,b,c); }

汉中市17883686953: 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; }

汉中市17883686953: 输入两个数,按位与后再输出 (c语言程序设计) -
良满田七: int main() { int a; int b; printf("input a and b:"); scanf("%d %d", &a, &b); printf("result = %d", a&b); return 0; }

汉中市17883686953: C语言中 输入两个整数,求 -
良满田七: #include<stdio.h> int main() {int i;int first;int secondr;int sum=0;printf("请输入任意两个整数(负数也可有):");scanf("%d %d",&first,&second); // if (first > second) {sum = first; first = second; second = first;} // 确保first小,second...

汉中市17883686953: c语言编写 编写一个简单的计算器,实现两个整型数的四则运算. -
良满田七: #include#include int main() { int a,b; char ch,pm='Y'; while(pm!='N') { cout<<"请输入第一个数:"< cin>>a; cout<<"请输入运算符号:"< cin>>ch; cout<<"请输入第二个数:"< cin>>b; if(ch=='+') cout<< else if(ch=='-') cout<< else if(ch=='*') cout<< else if(ch=='/') cout< cout<<"结束输入N,继续输入任意键!"< pm=getchar(); } return 1;} 要c++的行吗?还要换成c吗?

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