c语言用什么软件编辑,查找c语言答案的软件( 六 )


printf("xCh :%d\",j);/*输出xCh在str中出现的位置*/
}
p=p+1;/*指针地址移向str的下个字符*/
j++;/*j用于记录此时p的位置 , 在str中第一个字符时=0 , 第二个时=1 , 以此类推*/
}
if (i==0)/*当str中没有xCh这个字符时 , i=0*/
{
printf("Can Not Find The xCh! i=%d",i);/*在屏幕中提示无法找到str中的xCh , 并输出i=0*/
}
else
{
printf("\i=%d",i);/*\为换行*/
}
printf("\Parden>Y/N:");
fflush(stdin);/*清空计算机缓存*/
temp=getch();/*从屏幕中读取一个字符赋给temp*/
}
if(temp=='N'||temp=='n')/*当temp为N或n时*/
break;/*跳出循环*/
if(temp!='Y'&&temp!='y')/*当输入的temp不为Y、y、N、n时*/
{
printf("Wrong!You can only put Y(N) or y(n)\Please put again(Y/N):");
fflush(stdin);
temp=getch();
}
}
}
/*fflush(stdin)*/
实验八 结构体与共用体
一、 目的要求
1、 掌握结构体类型变量与数组的定义和使用;
2、 学会使用指针变量和结构体指针数组;
3、 按实验内容要求完成全程程序设计后才允许上机 。
二、 实验内容与步骤
1. 设计一个结构
struct student {
long no; /*学号*/
char name[10]; /*姓名*/
char sex; /*性别*/
int age; /*年龄*/
float score; /*平均成绩*/
}
2. 完成下列任务:
(1) 输入实际学生人数n (2<n<4);
(2) 输入每个学生的信息 , 组成结构数组 , 并输出;
(3) 统计男、女生人数并输出;
(4) 计算全班平均成绩并输出;
(5) 将低于全班平均成绩的学生信息按行输出
三、 上机要求
1. 可划分为若干个函数 , 或写成一个main( );
2. 要求输出格式有提示及相应数据 。
#include<stdio.h>
struct student
{
long no; /*学号*/
char name[10]; /*姓名*/
char sex; /*性别(gender)*/
int age; /*年龄*/
float score; /*平均成绩*/
}s[3];
void main()
{
int i,n,t,m,na;
float av,sum;
float temp;
clrscr();
m=0;
sum=0;
printf("The number of the studens:");
scanf("%d",&n);
printf("\");
for(i=0;i<n;i++)
{
printf("\No.");
scanf("%ld",&s[i].no);
printf("\Name:");
na=0;
while(na==0)
{
scanf("%s",&s[i].name);
if(strlen(s[i].name)>10)
printf("Wrong!You can only put 10 characters!\Name:");
else
na=1;
}
printf("\Gender:(W/M)");
t=0;
while(t==0)
{
scanf("%s",&s[i].sex);
if(s[i].sex!='W'&&s[i].sex!='w'&&s[i].sex!='m'&&s[i].sex!='M')
printf("Wrong!\Gender:");
else
t=1;
}
if(s[i].sex=='m'||s[i].sex=='M')
m++;
printf("\Age:");
scanf("%d",&s[i].age);
printf("\Score:");
scanf("%f",&temp);
s[i].score=temp;
}
for(i=0;i<n;i++)
{
sum=sum+s[i].score;
printf("\No.%ld\Name:%s\Gender:%c\Age:%d\Score:%.2f",s[i].no,s[i].name,s[i].sex,s[i].age,s[i].score);
}
av=sum/n;
printf("\The number of girl(s):%d\The number of boy(s):%d\",n-m,m);
printf("\The average of the score is:%.2f",av);
for(i=0;i<n;i++)
{
if (s[i].score<=av)
printf("\No.%ld; Name:%s; Gender:%c; Age:%d; Score:%.2f",s[i].no,s[i].name,s[i].sex,s[i].age,s[i].score);


特别声明:本站内容均来自网友提供或互联网,仅供参考,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。