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 void main(){int i,n,k=0;scanf("%d",&n);for(i=1;i<=3;i++){if(k<n%10) k=n%10;n=(n-n%10)/10;}printf("最大数字为%d",k);}

可以这样编程,先初始化三个变量都等于零,然后使用一个while的循环,直到输入合格的数据为止。

代码文本:

#include "stdio.h"

int main(int argc,char *argv[]){

int b,s,g,x;

printf("Enter x(int 99<x<1000)...
");

if(scanf("%d",&x)==1 && x>99 && x<1000){

b=x/100,s=x/10%10,g=x%10;

if(b>s)

b^=s,s^=b,b^=s;

if(b>g)

b^=g,g^=b,b^=g;

if(s>g)

s^=g,g^=s,s^=g;

printf("%d %d %d
",b,s,g);

}

else

printf("Input error, exit...
");

return 0;

}

运行样例:



//c语言代码:
#include <stdio.h>
int main()
{
int a,b,c,n;

if(scanf("%d",&n)!=1
||
!(n>99&&n<1000))
{
printf("输入的不是一个3位数\n");
return 0;
}
a=n%10;
b=n/10%10;
c=n/100;
if(b<a)
{
n=a;
a=b;
b=n;
}
if(c<a)
{
n=a;
a=c;
c=n;
}
if(c<b)
{
n=b;
b=c;
c=n;
}
printf("%d %d %d\n",a,b,c);
return 0;
}


再键盘上任意输入一个三位数,要正确的分离个十百位,并显示在屏幕上,用...
include "stdio.h"int main(){ int x,a,b,c;printf("请输入一个三位数:\\n");scanf("%d",&x);if(x>99&&x<10000){ a=(int)x\/100;\/*求百位*\/ b=(int)(x-100*a)\/10;\/*求十位*\/ c=(int)(x-100*a-10*b);\/*求个位*\/ printf("这三位分别为:%d %d %d\\n",a,b,c...

C语言输入一个三位正整数,输出各位位数上的至,并且将三位数逆序输出
include <stdio.h>int main(){ int a,b,c,n; scanf("%d",&n); a=n\/100; b=n\/10%10; c=n%10; printf("百位上的是%d,十位上的是%d,个位上的是%d,按位逆序的数是%d%d%d\\n", a,b,c,c,b,a); return 0;} ...

C语言:输入一个大于100的三位正整数n,输出100-n中满足条件的所有数...
include <stdio.h> void main(){ int i,a,b,c,n;scanf("%d",&n);for(i=100;i<=n;i++){ a=i \/ 100;b=i \/ 10 % 10;c=i % 10;if(a*b*c==32 && a+b+c==10)printf("%d\\n",i);} }

编程,输入一个三位整数,将其分解出百位,十位,各位,并求出各位之和以及...
\/\/将其分解出百位,十位,个位,并求出各位之和以及各位之积 a=c;t1=t1*atoi(&a);t2=t2+atoi(&a);} printf("百位:%c十位:%c个位:%c积:%d和:%d",c[0],c[1],c[2],t1,t2);} int main(int argc,char**argv){ int input=0;printf("请输入三位的整数(100~999),如果输入...

输入一个三位整数,判断其百位数字的奇偶性,输出百位数字及判断结果,c...
include <stdio.h>int main() {int n,result,eo;printf("输入一个三位正整数(q 结束):");while(scanf("%d",&n) == 1) {if(n < 100 || n > 999) {printf("输入错误。\\n");continue;}result = (n \/ 100) % 10;eo = result % 2;printf("百位是:%d,%s\\n",result,eo ?

“任意输入一个三位数,输出这个三位数的百位、十位和个位,并且计算十位...
include <stdio.h>int main(void){ int num, i = 0, sum = 0; int array[20]; \/\/ 利用一个数组临时接收 scanf("%d", &num); \/\/ 获取输入值 while (num > 0) { array[i++] = num % 10; \/\/ 依次存到数组中 num \/= 10; } for (num=i...

c语言程序编写 任意输入一个三位数,要求输出这个三位数的各个位的数...
a;int ta = a;int t[3];for (int i = 0; i < 3; i++ ) {t[i] = ta % 10;ta \/= 10;}if(t[0]*t[0]*t[0]+t[1]*t[1]*t[1]+t[2]*t[2]*t[2]==a)cout << "Yes" << endl;elsecout << "No" << endl;return 0;} 按位分解这个数的每一位然后判断 ...

编写程序,输入一个三位整数X(999=>X>=100),将其分解出百位,十位,个位...
printf("百位:%c 十位:%c 个位:%c 积:%d 和:%d",c[0],c[1],c[2],t1,t2);} int main(int argc, char** argv) { int input = 0;printf("请输入三位的整数(100~999), 如果输入0则退出程序:\\n\\n");while(1) { if(scanf("%d",&input) == 1) { if(input == ...

“任意输入一个三位数,输出这个三位数的百位、十位和个位,并且计算十位...
printf("输入一个三位数:"); scanf("%d", &a); if (a > 999 || a < 100) printf("输入错误!"); else { b = a \/ 100; c = a \/ 10 % 10; d = a % 100 % 10; e = b + c + d; printf ("百位是%d,十位是%d,个位是%d,各个位数的和为%d", b, c, d, e); } return 0...

C语言题,输入一个三位数,个十百位数字换行输出。
你好!!程序可以输入任意长度的数字,然后分行输出:include <stdio.h> int main(){long int x; int i=0;int ii=0;int shu[20]={0};scanf("%ld",&x);for(;;){shu[i] = x % 10;x = x \/ 10;i++;if( x < 10){shu[i]=x;break;} }for(;i>=0;i--)printf("%d\\n...

若羌县15312685335: C语言,输入三数按照从小到大顺序输出 -
辉璧新博: scanf加取地址& #include <stdio.h> main() {int a,b,c,d;scanf("%d%d%d",&a,&b,&c);if(a>b){d=a;a=b;b=d;}if(b>c){d=b;b=c;c=d;}printf("%d %d %d",a,b,c); }

若羌县15312685335: c语言编写程序从键盘输入3个整数,按由小到大输出 -
辉璧新博: #include <stdio.h>#define swap(a, b) { t = a; a = b; b = t; } int main() {int a, b, c, t;scanf("%d%d%d", &a,&b,&c);if(a < b) swap(a, b);if(a < c) swap(a, c);if(b < c) swap(b, c);printf("%d %d %d\n", a,b,c); }

若羌县15312685335: 用C语言描述对于输入的任意三个整数,将它们按从小到大的顺序输出? -
辉璧新博: 1、输入三个整数x,y,z,请把这三个数由小到大输出. 2、所需要的开头代码,#include "stdio.h"#include "conio.h",预处理命令,表示程序包含conio.h库文件conio.h库文件定义了通过控制台进行数据输入和数据输出的函数. 3、下面...

若羌县15312685335: 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("从小到大...

若羌县15312685335: 用C语言输入3个整数,怎么按从小到大的顺序输出? -
辉璧新博: #includevoid f(int* x,int* y,int* z) { int sum=*x+*y+*z; //三个数之和 //求最大数 int tmp=(*x>*y)?*x:*y; int max=(tmp>*z)?tmp:*z; //求最小数 tmp=(*xint min=(tmp//中间的数为sum减去最大数和最小数 int mid=sum-max-min //按从小到大重新赋值 *x=min; *y=mid; *z=max }int main() { int a=10,b=-50,c=20;f(&a,&b,&c);printf("%d %d %d\n",a,b,c);return 0; }

若羌县15312685335: C语言编程题,从键盘输入任意3个数,按从小到大的顺序输出 -
辉璧新博: #include "stdio.h" main() { int x,y,z,t; scanf("%d%d%d",&x,&y,&z); if (x>y) { t=x;x=y;y=t; } /*交换x,y的值*/ if(x>z) { t=z;z=x;x=t; }/*交换x,z的值*/ if(y>z) { t=y;y=z;z=t; }/*交换z,y的值*/ printf("small to big: %d %d %d\n",x,y,z); }

若羌县15312685335: C语言:::::.对于输入的任意三个整数,将它们按从小到大的顺序输出. -
辉璧新博: 1 读入三个数. 2 循环比较大小,令三个数从小到大排序. 3 输出结果. 代码: #include int main() {int a,b,c,t;#define swap(m,n){t = m; m = n; n = t;}//交换值宏.scanf("%d%d%d",&a,&b,&c);//输入三个数.if(a>b) swap(a,b);if(a>c)swap(a,c);//经过以上两步,a为最小值.if(b>c)swap(b,c);//b比c小.printf("%d %d %d\n", a,b,c);//输出结果.return 0; }

若羌县15312685335: 用C语言编程 : 从键盘输入3个数,按从小到大输出 -
辉璧新博: 如果只是3个数的话 一:如果是从大到小输出的话 #includevoid main() { int x,y,z,t; scanf("%d%d%d",&x,&y,&z); if (x>y) {t=x;x=y;y=t;} /*交换x,y的值*/ if(x>z) {t=z;z=x;x=t;}/*交换x,z的值*/ if(y>z) {t=y;y=z;z=t;}/*交换z,y的值*/ printf("small to big: %...

若羌县15312685335: c语言编程的题 “从键盘输入3个数,使其按从小到大的顺序排列输出.” 感谢各位帮忙! -
辉璧新博: #includevoid sort(int &a,int &b)//对两个数进行排序 { int d; if(a>b) { d=a;a=b;b=d; } } void main() { int a,b,c,d; printf("输入三个数"); scanf("%d%d%d",&a,&b,&c); sort(a,b); sort(a,c); sort(b,c); printf("%d %d %d",a,b,c); }

若羌县15312685335: C语言程序题目:由键盘输入三个数a,b,c,按从小到大的顺序输出这三个数. -
辉璧新博: C语言程序如下: #include <stdio.h> 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 ...

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