已解决问题 - 浏览224次

下一个已解决问题
永不放弃永不放弃

高级书童

修改一个C程序

这个C程序运行时先显示一个菜单,输入选项后回车,再输入数据,就可以运算.但每个选项运算完后却不能返回菜单.
#include<stdio.h>
void f2()
{
int x,y;
printf("please input x:");
scanf("%d",&x);
y=5*x-3;
printf("%d",y);
}
void f3()
{
int a,sum=0,i=1,n,temp;
printf("please input a,n:");
scanf("%d%d",&a,&n);
temp=a;
while(i<=n)
{
sum=sum+a;
a=a*10+temp;
i++;
}
printf("sum=%d ",sum);
}
void f4()
{
int i=0,j=0,a[3][3],s=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
printf("input 9ge shu:");
scanf("%d",&a[i][j]);
for(j=0;j<3;j++)
s=s+a[i][j];
printf("the result is %d ",s);
}
main()
{
char c;
menu:
{
printf("* * * * * this is a menu* * * * * ");
printf("* *please input 1 to 5 to choose* * ");
printf("1 goto the No.1 ");
printf("2 goto the No.2 ");
printf("3 goto the No.3 ");
printf("4 goto the No.4 ");
printf("5 goto the No.5 ");
printf("please enter your choice ");
c=getchar();
switch(c)
{
case '1': { clrscr(); printf("this is No4-9 "); f1();getch();}goto menu;
case '2': { clrscr(); printf("this is No5-5 "); f2();getch();}goto menu;
case '3': { clrscr(); printf("this is No6-3 "); f3();getch();}goto menu;
case '4': { clrscr(); printf("this is No7-3 "); f4();getch();}goto menu;
case '5': { clrscr(); printf("this is No8-1 "); f5();getch();}goto menu;
default:printf("selection error! ");
}
}
}
int f1()
{
int F,C;
printf("please enter F:");
scanf("%d",&F);
C=5.0/9*(F-32);
printf("C=%5.2d",C);
}
f5()
{
int m,t,n,a,b;
printf("input a,b:");
scanf("%d%d",&a,&b);
if(a>b)
{t=b;b=a;a=t;}
m=max( a, b);
printf("max gy is:%d ",m);
n=a*b/m;
(剩下的输不下了)

还可输入300个字

请输入上图中的验证码,字母不区分大小写。

点击查看更多 c 程序 修改 相关信息

大刚大刚

伴读书童

最佳答案 - 由提问者2007-12-07 16:25:04选出

default:printf("selection error! ");上加入goto menu;就行了

0 0

还可输入300个字

请输入上图中的验证码,字母不区分大小写。

提问者对最佳答案的评价 *

谢谢!

返回知识堂首页>>

猜你喜欢看

更多
1