编写一个程序,从键盘输入3个数字,输出它们按从小到大

作者&投稿:邰欢 (若有异议请与网页底部的电邮联系)
~

C语言程序如下:

#include<stdio.h>

intmain()

{

inta,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);

return0;

}

扩展资料:

程序实现思路

1、通过elseif多次判断来输出。

2、进行多次判断,匹配对应的值来输出,

假设C<A 且C<B 且B<A  则从大到小输出为A,B,C 

用代码表示为if(c<a&&c<b&&b<a){

System.out.println("老大"+a,"老二"+b+"老三"+c);

}elseif(比较条件){

}



在C语言中,如果只需要对三个数字进行排序,那么可以不必使用复杂的排序算法。可以通过比较和交换这三个数来轻松地将它们排序。
#include <stdio.h>
int main() {
int a, b, c, temp;
// 从用户获取三个数
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
// 比较并交换,确保a是最小的
if (a > b) {
temp = a;
a = b;
b = temp;
}
if (a > c) {
temp = a;
a = c;
c = temp;
}

// 现在比较并交换b和c,以确保b小于c
if (b > c) {
temp = b;
b = c;
c = temp;
}
// 输出结果
printf("The numbers in ascending order are: %d %d %d\n", a, b, c);
return 0;
}

编写一个程序,从键盘输入3个数,打印出这3个数的和、平均值、乘积、最...
答:printf("三个数的和%.1f\n",sum);printf("三个数的平均值%.2f\n",d);printf("三个数的积%.1f\n",e);printf("三个数中最大值是%d\n",max);printf("三个数中最小值是%d\n",min);}

编写程序,从键盘输入3个整数,要求设3个指针变量p1、p2、p3,使p1指向3...
答:include<stdio.h>int main(){int a,b,c,*p1=&a,*p2=&b,*p3=&c,*t; scanf("%d%d%d",p1,p2,p3); if(*p1<*p2){t=p1;p1=p2;p2=t;} if(*p1<*p3){t=p1;p1=p3;p3=t;} if(*p2<*p3){t=p2;p2=p3;p3=t;} printf("%d %d %d\n",*p3,*p2,*p1); return 0;} ...

编写一个java程序,从键盘输入一元二次方程的3个系数a,b和c,输出这个方...
答:string_b = JOptionPane. showInputDialog("输入方程中的一次项系数");b = Double.parseDouble(string_b);string_c = JOptionPane. showInputDialog("输入方程的常数项");c = Double.parseDouble(string_c);D = b*b-4*a*c; // 计算根的判别式 if( D > 0 ){ // 有二个不相等的实数...

编写一个程序,从键盘输入3个数字,输出它们按从小到大
答:C语言程序如下:include<stdio.h> intmain(){ inta,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\n",a,b,c);return0;} ...

用C++编写一个程序,从键盘上输入三个整数,判断这三个数的大小,并将这...
答:include<iostream>using namespace std;int main(){int a,b,c,t;cout<<"请输入3个数,空格隔开:";cin>>a;cin>>b;cin>>c;t=a;if(a<b){a=b;b=t;}if(a<c){t=a;a=c;c=t;}t=b;if(b<c){b=c;c=t;}cout<<"从大到小的顺序为:"<<a<<","<<b<<","<<c<<endl;...

编写一个程序,从键盘输入三个整数a.b.c,计算表达式a+b*c的值,并输出...
答:1、以C#控制台应用程序为例:Console.WriteLine("输入3个整数,之间以逗号分隔,回车键结束...");string str = Console.ReadLine(); //读入用户输入信息 string[] input = str.Split(new char[] { ',' }); //以逗号为分隔符,分离出各项 if (input.Count() == 3) //不是3,用户输入...

编写一个C++程序,从键盘输入3个字符串,在屏幕上输出其中最大者。_百度...
答:int main(){ string s1, s2, s3, s4;cout << "请输入第一个字符串:" <<endl;cin >> s1;cout << "请输入第二个字符串" <<endl;cin >> s2;cout << "请输入第三个字符串" <<endl;cin >> s3;s4 = comp(comp(s1,s2), s3);cout << "最大的字符串为: "<< s4 <<endl;r...

编写程序,任意从键盘中输入3个整数,求出这3个整数的和?
答:public static void main(String[] args) { Scanner scan = new Scanner(System.in);int num1 = 0, num2 = 0, num3 = 0;System.out.print("请输入第一个数:");num1 = scan.nextInt();System.out.print("请输入第二个数:");num2 = scan.nextInt();System.out.print("请输入第...

编写一个c语言程序,从键盘输入三个数,要求按从大到小的顺序输出这三个...
答:{ int a,b,c;int maxNum,minNum,midNum;scanf("%d %d %d",&a,&b,&c);if (a>b){ if (a>c){ maxNum = a;if (b>c){ midNum = b;minNum = c;} else { midNum = c;minNum = b;} } else { maxNum = c;midNum = a;minNum = b;} } printf("%d %d %d\n",...

C#编程:编写一个程序,从键盘上输入3个数,输出这3个数的积及它们的和...
答:class Program { static void Main(string[] args){ Console.Write("输入你的第一个数:");string d1 = Console.ReadLine();Console.Write("输入你的第二个数:");string d2 = Console.ReadLine();Console.Write("输入你的第三个数:");string d3 = Console.ReadLine();Console.WriteLine("...