今天继续问有关C语言的题

[复制链接]
查看11 | 回复1 | 2010-12-30 00:22:22 | 显示全部楼层 |阅读模式
题目是这样
编程:做一个小系统,要求:
一、设计一个菜单程序: 1、形成的新字符串

2、连接后的字符串

3、狗熊吃包谷

4、学生的平均分
5、再见
我目前已经完成的部分:
#include
#include
#include
#include
#define N 8
void xin();
void lian();
void yumi();
void pjf();
int menu_select();
intmain()
{
for(;;){
switch(menu_select())
{ case 1:

xin();

break;


case 2:

lian();

break;

case 3:

yumi();

break;
case 4:

pjf();

break;
case 5:

printf("Goodbye!\n\n\n");

exit(0);
}

}
return 0;
}
int menu_select()
{ char s;
int cn;
printf("1、形成新的字符串\n");
printf("2、连接两个字符串\n");
printf("3、狗熊吃包谷\n");
printf("4、求学生的平均分\n");
printf("5、Goodbye!\n");
printf("Input 1-5:");
do
{ s=getchar();
cn=(int)s-48;
}while(cn5);
return cn;
}
void xin()
{char s[100],t[100],u[100];
int a,b,c=0,i,j;
printf("\n请输入第一个字符串:");
scanf("%s",s);
printf("\n请输入第二个字符串:");
scanf("%s",t);
a=strlen(s);
b=strlen(t);
for(i=0;i
#define N 8
struct slist
{ double s;
struct slist *next;
};
typedef struct slist STREC;
double fun(STREC *h)
{

int n=0;
double sum=0;

double av;

STREC *p;

p=h->next;

while(p)

{

n++;

sum+=p->s;

p=p->next;

}

av=sum/n;

return av;
}
STREC *creat(double *s)
{ STREC *h,*p,*q;
int i=0;
h=p=(STREC*)malloc(sizeof(STREC));p->s=0;
while(is=s;i++;p->next=q;p=q;
}
p->next=0;
return h;
}
outlist(STREC *h)
{ STREC *p;
p=h->next;printf("head");
do
{printf("->%4.1f",p->s);p=p->next;
}
while(p!=0);
printf("\n\n");
}
int main()
{ double s[N]={85,76,69,85,91,72,64,87},ave;
STREC *h;
h=creat(s);outlist(h);
ave=fun(h);
printf("ave=%6.3f\n",ave);
return 0;
}

回复

使用道具 举报

千问 | 2010-12-30 00:22:22 | 显示全部楼层
不就合一起么 有什么难的#include#include#include#include#include#define N 8struct slist{ double s;struct slist *next;};typedef struct slist STREC;void xin();void lian();void yumi();void pjf();int menu_select();intmain(){ for(;;){switch(menu_s
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行