#include <stdioh>
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;
}
}
union{int i[2]; long k; char c[4]; }r,s=&r;
这个联合体中int i[2]占得空间最大,8个字节,所以整个联合体就是8个字节,
i[0]=0x39,因为联合体中所有成员使用同一块内存空间,i[0]在内存中的布局是
0x(表示16进制) 39 00 00 00
所以c[0]=0x39即57即字符'9'
用Turbo
C
做的代码如下:
#include<stdioh>
#include<conioh>
void
main()
{ int
stu[100][5];
int
ia,ib,ic;
ia=0;
printf("input
the
student's
number('0'
to
end):\n");
scanf("%d",&stu[ia][0]);
while(stu[ia][0]!=0&&ia!=100)
{ printf("input
the
1
score:");
scanf("%d",&stu[ia][1]);
printf("input
the
2
score:");
scanf("%d",&stu[ia][2]);
printf("input
the
3
score:");
scanf("%d",&stu[ia][3]);
printf("input
the
4
score:");
scanf("%d",&stu[ia][4]);
ia++;
if(ia==100)
{ printf("data
overflow!\n");
break;
}
printf("input
the
number:");
scanf("%d",&stu[ia][0]);
}
printf("\ninput
the
number
of
the
student:");
scanf("%d",&ib);
for(ic=0;ic<ia;ic++)
{ if(ib==stu[ic][0])
break;
}
if(ic==ia)
printf("can
not
find
the
information!\n");
else
{ printf("number\t1score\t2score\t3score\t4score\n");
printf("%6d\t%6d\t%6d\t%6d\t%6d\n",stu[ic][0],stu[ic][1],stu[ic][2],stu[ic][3],stu[ic][4]);
}
fflush(stdin);
getchar();
}
这个不太完美,因为定义的数组是整型的,所以不能输入字符串,也就不能输入学生姓名,可以再定义一个字符型的二维数组;另外学号也不能以零开头,否则输出信息的时候0会被省掉,如果需要改进一下请追问,希望能帮到你
以上就是关于C语言switch语句编个小程序全部的内容,包括:C语言switch语句编个小程序、一个C小程序、C语言编写程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)