C语言switch语句编个小程序

C语言switch语句编个小程序,第1张

#include <stdio.h>

void main()

{

int age

printf("please input the child age:")

scanf("%d",&age)

switch(age)

{

case 2:

case 3: printf("%d,enter the Lower class.\n",age)break

case 4: printf("%d,enter the Middle class.\n",age)break

case 5:

case 6: printf("%d,enter the Higher class.\n",age)break

default : printf(" you chlid shuld goto more Higher class.\n")break

}

}

首先 int 型 的函数就应该有返回值为int型的数值。

2.想修改数燃高明组里 的值用指针最好。

3 main 函数里的 scanf("%d",&shf[][])scanf输入的是地址的值,所以要加&

4.一般数组第一个数是a[0][0],你数组取值是从a[1][1]开始,少了一行的数,浪费。。。

先说这么多

#include<stdio.h>

void hanshu1(int *p)

{

int b,d,c,e,f,i,j

b=0

d=0

for(i=0i<39i++)

for(j=0j<13j++)

{

b=b+(*p+i)+j

c=b/12

printf("%d号学生月平均花费%d元\n",i,c)

}

d=d+b

e=12*39

f=d/e

printf("所有学生平均花费%d元",&f)

}

void hanshu2(int *q)

{

int a=0,b=0,i,j

for(i=0i<39i++)

for(j=0j<13j++)

a=j+1

b=(*q+i)+j

if((*q+i)+j<(*q+i)+a)

{

b=(*q+i)+a

}

printf("最高生活费用皮告的是%d号学生,第%d月,花费%d元",i,a,b)

}

void main()

{ int x

int shf[39][12]/*shf为生活费*/

int stu,mon

printf("请输入学生的生活费:\n")

for(stu=0stu<39stu++)

for(mon=0mon<13mon++)

scanf("%d",shf[stu][mon])

for(stu=0stu<39stu++)

for(mon=0mon<13mon++)

printf("%d号学生的%d月花费为:%d元",stu,mon,shf[stu][mon])

printf("请选择需要的 *** 作:\n")

printf("每个学生的月平均生活费用和全部学生平均生活费*****1\n")

printf("最高月生活费的人和月份and费用*****2\n")

printf("退出系统****3\n"念缺)

scanf("%d",&x)

switch (x)

{

case 1:

hanshu1(&shf)

break

case 2:

hanshu2(&shf)

break

default:

printf("error")

}

}

改了下,你回去调试,不行再CALL 我

肯定可以的,只要你程序橘洞告是对的,这个又不相互影响,switch是和case一起使用的,还有break

你可以圆明还一下你的c语言书上是怎么写的,你那个程序switch括弧里面那样写好像是不行的,就算不报错,但是应该不能输出正确颤链答案


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8283590.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-15
下一篇 2023-04-15

发表评论

登录后才能评论

评论列表(0条)

保存