作业帮 > 综合 > 作业

从键盘输入a,b,c 从小到大一次输出.请画出流程图,并写出程序

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/29 15:37:00
从键盘输入a,b,c 从小到大一次输出.请画出流程图,并写出程序
看吧:
流程图:
变量a |变量b |变量c
↓ ↓ ↓
|————-------| ↓
| ?a>b | ↓
|————-------| ↓
真↓ ↓假 ↓
|-----------| ————--→↓
| a与b | ↓
| 交换值 | ↓
|------------| ↓
↓ ↓
|-------------------------------|
| ?b>c |
|-------------------------------|
真↓ 假↓
|------------------| ↓
| b与c交换值 | ↓
|-----------------| ↓
↓ ↓
|--------------------------|
| 输出a,b,c |
|--------------------------|

|--------------------|
| 程序结束 |
|--------------------|
C代码:
#include
void main(){
long a,b,c,temp;
printf("请输入a,b,c的值:");
scanf("%ld%ld%ld",&a,&b,&c);
if(a>b){=temp=a;a=b;b=temp;}//交换a、b的值,保持a、b是从小到大排列
if(b>c){=temp=b;b=c;c=temp;}//交换b、c的值,保持b、c是从小到大排列
printf("a>b>c输出:%ld>%ld>%ld",a,b,c);//输出a,b,c
//程序结束
}
Java代码:
import java.util.*;
public class oput_abc{
public static void main(String args[])
{
long a,b,c;
System.out.print("请输入a,b,c的值:");
Scanner keyIn=new Scanner(System.in);
a=keyIn.nextLong();b=keyIn.nextLong();c=keyIn.nextLong(); // 输入值给 a,b,c
if(a>b){a=a^b^a;b=a^b^b;}//交换a,b值,保持ac){b=b^c^b;c=b^c^c;}//交换b,c值,保持b b then
temp=a
a=b
b=temp
end if
if b>c then
temp=b
b=c
c=temp
end if
msgbox "a>b>c输出:" & a & ">" & b & ">" & c
//演示结束
end su