當前位置:首頁 » 編程語言 » c語言程序設計課程設計

c語言程序設計課程設計

發布時間: 2022-05-22 03:47:08

A. c語言程序設計 (學生選修課程設計)

這是我做的,你看是否滿意?可能有點大,但也沒辦法呀,你的題目也比較大,呵呵!所以,如果滿意,多給我追加點分!
#include
"stdio.h"
#include
"stdlib.h"
#include
"string.h"
typedef
struct
course
{
char
number[15],name[25];
int
kind,time,lessontime,practicetime,credit,term;
}type;
FILE
*fp1;
void
overview();
//瀏覽函數,負責瀏覽整個課程信息
void
seek();
//查詢函數,負責查詢課程信息
void
choose_course();//選課函數,負責讓用戶選課
void
out(type
temp);
void
input();
int
main()
{
int
n,i;
if((fp1=fopen("course_information.txt","wb"))==NULL)
{printf("創建文件失敗!\n");exit(0);}
printf("請輸入要存儲的課程數目:\n");
scanf("%d",&n);
printf("開始創建文件,請輸入課程信息:\n\n");
for(i=0;i<n;i++)
{
printf("請輸入第%d門課程的信息:\n",i+1);
input();
printf("\n");
}
printf("如想瀏覽整個課程信息,請輸入1;如想查詢課程信息,請輸入2;
如想進行選課,請輸入3;如想結束選修課系統,請輸入0!\n");
while((scanf("%d",&n))!=EOF)
{
if(n==1)
overview();
if(n==2)
seek();
if(n==3)
choose_course();
if(n==0)
exit(0);
printf("\n\n如想繼續操作,只要按規則輸入你要進行的操作即可!\n規則:如想瀏覽整個課程信息,請輸入1;如想查詢課程信息,請輸入2;如想進行選課,請輸入3!\n");
}
printf("歡迎您使用此程序進行選課,謝謝!\n");
fclose(fp1);
return
0;
}
void
input()
{
course
c_a;
printf("請輸入課程編碼:
");
scanf("%s",c_a.number);
printf("請輸入課程名:
");
scanf("%s",c_a.name);
printf("請輸入課程性質:限選課,請輸入1;選修課,請輸入2;必修課,請輸入3!
");
scanf("%d",&c_a.name);
printf("請輸入課程總學時:
");
scanf("%d",&c_a.time);
printf("請輸入課程授課時間:
");
scanf("%d",&c_a.lessontime);
printf("請輸入課程實驗或實踐時間:
");
scanf("%d",&c_a.practicetime);
printf("請輸入課程學分:
");
scanf("%d",&c_a.credit);
printf("請輸入課程所在的學期,比如第二學期,就輸入2即可。");
scanf("%d",&c_a.term);
fwrite(&c_a,sizeof(struct
course),1,fp1);//將一個結構體元素寫入文件中
}
void
out(type
temp)
{
printf("課程代碼:
%s\n課程名:
%s\n",temp.number,temp.name);
printf("課程名:
%s\n",temp.name);
if(temp.kind==1)
printf("課程性質:
Limited
optional
course\n");
else
if(temp.kind==2)
printf("課程性質:
Optional
course\n");
else
if(temp.kind==3)
printf("課程性質:
Required
Courses\n");
else
printf("該編碼系統不認識,即無對應的課程性質存在!\n");
printf("課程總學時:
%d\n課程授課學時:
%d\n實驗或上機學時:
%d\n學分:
%d\n課程開課學期:
%d\n\n",temp.time,temp.lessontime,temp.practicetime,temp.credit,temp.term);
}
void
overview()
{
rewind(fp1);
course
temp;
printf("整個課程信息如下:\n");
while((fread(&temp,sizeof(type),1,fp1))!=0)
out(temp);
}
void
seek()
{
int
judge,credit=0,kind=0;
char
a='N';
course
temp;
printf("如想按學分查詢,請輸入1;如想按課程性質,請輸入2:\n");
scanf("%d",&judge);
rewind(fp1);
//將文件指針位置置為開頭
if(judge==1)
{
printf("請輸入要查詢的學分:\n");
scanf("%d",&credit);
while((fread(&temp,sizeof(type),1,fp1))!=0)
if(credit==temp.credit)
out(temp);
}
else
if(judge==2)
{
printf("請輸入你要查找課程的性質(限選課,請輸入1;選修課,請輸入2;必修課,請輸入3):");
scanf("%d",&kind);
while((fread(&temp,sizeof(type),1,fp1))!=0)
if(temp.kind==kind)
out(temp);
}
else
printf("不好意思,無此類查詢!\n");
}
void
choose_course()
{
rewind(fp1);
course
temp;
int
judge=1,n=0,time=0,credit=0;
char
choose[20][20];
r1:
printf("請開始填寫課程編號進行選課:\n");
while(judge==1)
{
printf("請輸入你所選課程的標號:
");
scanf("%s",choose[n]);
n++;
printf("如想繼續選課,請輸入1;如想提交,請輸入0!\n");
scanf("%d",&judge);
}
while((fread(&temp,sizeof(type),1,fp1))!=0)
{
for(int
i=0;i<n;i++)
if(strcmp(temp.number,choose[i])==0)
{time=time+temp.time;credit=temp.credit;break;}
}
if(time<270||credit<40)
goto
r1;
printf("你所選的課為:\n");
while((fread(&temp,sizeof(type),1,fp1))!=0)
{
for(int
i=0;i<n;i++)
if(strcmp(temp.number,choose[i])==0)
{out(temp);break;}
}
}

B. C語言程序 課程設計

以前編的 供你參考下 這東西沒人會給你編一個符合你的要求的。還是自己琢磨琢磨好。
#include "stdio.h"
#include "string.h"
struct student
{int num;
char name[10];
char sex[10];
char brith[20];
char academy[20];
float score[5];
float average;
}stu[30];
int m=0,o;
void main()
{
void SR();
void TJ();
void CX();
void SC();
void CR();
void XG();
int n;
printf("請輸入統計人數:");
scanf("%d",&o);
do{printf(" # %d學生 4門課的統計程序 #\n 1 成績錄入;\n 2 成績查詢;\n 3 成績統計;\n 4 刪除錄入;\n 5 插入學生 \n 6 修改學生 \n 7 退出",o);
printf("\n輸入1-7選擇。請選擇:");
scanf("%d",&n);
if(n==1) SR();
else if(n==2) CX();
else if(n==3) TJ();
else if(n==4) SC();
else if(n==5) CR();
else if(n==6) XG();
else if(n==7) printf("謝謝使用");
else printf("無此選項!自動返回!\n");}
while(n!=7);
}

void SR()
{int y,i,j,t,k,n; float x;
if(m==1)
{printf("成績已錄入,數字鍵返回");
scanf("%d",&y);
goto loop;}
for(i=0;i<o;i++)
{printf("輸入第%d名同學的信息\n",i+1);
printf("學號:");
scanf("%d",&stu[i].num);
printf("\n姓名:\n");
scanf("%s",&stu[i].name);
printf ("\n性別:\n");
scanf ("%s",&stu[i].sex);
printf("\n出生日期:\n");
scanf("%s",&stu[i].brith);
printf("\n系別:\n");
scanf("%s",&stu[i].academy);
printf("\n分數:\n");
for(j=0;j<4;j++)
{printf("第%d科",j+1);
scanf("%f",&stu[i].score[j]);}
x=0;
for(t=0;t<4;t++)
x=x+stu[i].score[t];
stu[i].average=x/4;}
printf("輸入的成績為:\n");
printf("學號 姓名 性別 出生日期 系別 第一科 第二科 第三科 第四科\n");
for(k=0;k<o;k++)
printf("%-6d%-10s%-6s%-13s%-7s%-7.2f%-9.2f%-9.2f%-9.2f\n",stu[k].num,stu[k].name,
stu[k].sex,stu[k].brith,stu[k].academy,stu[k].score[0],stu[k].score[1],stu[k].score[2],stu[k].score[3]);
printf("重新輸入請按 0,其他數字鍵返回");
scanf("%d",&n);
if(n==0)
SR();
else m=1;
loop:{};}

void CR()
{int i,k,j,t,n,w=-1;float x;
if(m==0)
{printf("請先輸入成績!\n");
goto loop;};
printf("插入的學號:");
scanf("%d",&stu[o].num);
printf("\n插入的姓名:\n");
scanf("%s",&stu[o].name);
printf ("\n插入的性別:\n");
scanf ("%s",&stu[o].sex);
printf("\n插入的出生日期:\n");
scanf("%s",&stu[o].brith);
printf("\n插入的系別:\n");
scanf("%s",&stu[o].academy);
printf("\n插入的分數:\n");
for(j=0;j<4;j++)
{printf("第%d科",j+1);
scanf("%f",&stu[o].score[j]);}
o=o+1;
for(i=0;i<o;i++)
{x=0;
for(t=0;t<4;t++)
{x=x+stu[i].score[t];}
stu[i].average=x/4;}
printf("各學生成績:\n");
{printf("學號 姓名 性別 出生日期 系別 第一科 第二科 第三科 第四科 平均\n");
for(k=0;k<o;k++)
printf("%-6d%-10s%-6s%-13s%-7s%-7.2f%-9.2f%-9.2f%-9.2f%-9.1f\n",stu[k].num,stu[k].name,
stu[k].sex,stu[k].brith,stu[k].academy,stu[k].score[0],stu[k].score[1],stu[k].score[2],stu[k].score[3],stu[k].average);}
printf("重復插入請按 0,其他數字鍵確認");
scanf("%d",&n);
if(n==0)
CR();
loop:{};}

void SC()
{int k,j,t,n,w=-1;
if(m==0)
{printf("請先輸入成績!\n");
goto loop;};
printf("各學生成績:\n");
{printf("學號 姓名 性別 出生日期 系別 第一科 第二科 第三科 第四科 平均\n");
for(k=0;k<o;k++)
printf("%-6d%-10s%-6s%-13s%-7s%-7.2f%-9.2f%-9.2f%-9.2f%-9.1f\n",stu[k].num,stu[k].name,
stu[k].sex,stu[k].brith,stu[k].academy,stu[k].score[0],stu[k].score[1],stu[k].score[2],stu[k].score[3],stu[k].average);}
chucuo:printf ("你要刪除的學號:");
scanf("%d",&j);
for(t=0;t<o;t++)
{if (stu[t].num==j)w=t;}
if(w!=-1)
{o=o-1;
for (k=w;k<o;k++)
{stu[k].num=stu[k+1].num;
strcpy(stu[k].name,stu[k+1].name);
strcpy(stu[k].sex,stu[k+1].sex);
strcpy(stu[k].brith,stu[k+1].brith);
strcpy(stu[k].academy,stu[k+1].academy);
stu[k].score[0]=stu[k+1].score[0];
stu[k].score[1]=stu[k+1].score[1];
stu[k].score[2]=stu[k+1].score[2];
stu[k].score[3]=stu[k+1].score[3];
stu[k].average=stu[k+1].average;}}
if (w==-1) {printf("輸入學號有誤,請從新輸入:");goto chucuo;};
printf("刪除後各學生成績:\n");
printf("學號 姓名 性別 出生日期 系別 第一科 第二科 第三科 第四科 平均\n");
for(k=0;k<o;k++)
{printf("%-6d%-10s%-6s%-13s%-7s%-7.2f%-9.2f%-9.2f%-9.2f%-9.1f\n",stu[k].num,stu[k].name,
stu[k].sex,stu[k].brith,stu[k].academy,stu[k].score[0],stu[k].score[1],stu[k].score[2],stu[k].score[3],stu[k].average);}
printf("重復刪除請按 0,其他數字鍵確認");
scanf("%d",&n);
if(n==0)
SC();
loop:{};}

void TJ()
{
int k,i,j,a[30],t; float n[30],q;
if(m==0)
{printf("請先輸入成績!\n");
goto loop;};
printf("各學生成績:\n");
{printf("學號 姓名 性別 出生日期 系別 第一科 第二科 第三科 第四科 平均\n");
for(k=0;k<o;k++)
printf("%-6d%-10s%-6s%-13s%-7s%-7.2f%-9.2f%-9.2f%-9.2f%-9.1f\n",stu[k].num,stu[k].name,
stu[k].sex,stu[k].brith,stu[k].academy,stu[k].score[0],stu[k].score[1],stu[k].score[2],stu[k].score[3],stu[k].average);}
for(i=0;i<o;i++)
a[i]=i;
for(i=0;i<o;i++)
n[i]=stu[i].average;
for(j=0;j<o-1;j++)
for(i=0;i<o-1-j;i++)
if(n[i]<n[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;
q=n[i];n[i]=n[i+1];n[i+1]=q;}
printf("按平均分排序\n");
{printf("學號 姓名 性別 出生日期 系別 第一科 第二科 第三科 第四科 平均\n");
for(k=0;k<o;k++)
printf("%-6d%-10s%-6s%-13s%-7s%-7.2f%-9.2f%-9.2f%-9.2f%-9.1f\n",stu[a[k]].num,stu[a[k]].name,
stu[a[k]].sex,stu[a[k]].brith,stu[a[k]].academy,stu[a[k]].score[0],stu[a[k]].score[1],stu[a[k]].score[2],stu[a[k]].score[3],stu[a[k]].average);}
chucuo:{printf("1 按第一科排序\n2 按第二科排序\n3 按第三科排序\n4 按第四科排序\n請輸入:");
scanf("%d",&k);
if(k==1) j=0;
else if(k==2) j=1;
else if(k==3) j=2;
else if(k==4) j=3;
else {printf("出錯,重新輸入\n");goto chucuo;}
for(i=0;i<o;i++)
{n[i]=stu[i].score[j];
a[i]=i;};
for(k=0;k<o-1;k++)
for(i=0;i<o-1-k;i++)
if(n[i]<n[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;
q=n[i];n[i]=n[i+1];n[i+1]=q;}
{printf("按第%d科排序結果:\n",j+1);
printf("學號 姓名 性別 出生日期 系別 科目\n");
for(k=0;k<o;k++)
printf("%-6d%-10s%-6s%-13s%-7s%-7.2f\n",stu[a[k]].num,stu[a[k]].name,
stu[a[k]].sex,stu[a[k]].brith,stu[a[k]].academy,stu[a[k]].score[j]);}
printf("繼續按1,其他數字鍵返回");
scanf("%d",&i);
if(i==1) goto chucuo;
loop:{};}}

void CX()
{
int x,y,k,t,i,j,q=0;
if(m==0)
{printf("請先輸入成績!\n");
goto loow;};
looq:printf("1 按學號查詢\n2 查詢不及格學生\n其他數字鍵退出\n");
scanf("%d",&x);
if(x==1)
loop:{printf("輸入學號:\n");
scanf("%d",&y);
j=0;
for(k=0;k<o;k++)
if(y==stu[k].num)
{printf("學號 姓名 性別 出生日期 系別 第一科 第二科 第三科 第四科 平均\n");
printf("%-6d%-10s%-6s%-13s%-7s%-7.2f%-9.2f%-9.2f%-9.2f%-9.1f\n",stu[k].num,stu[k].name,
stu[k].sex,stu[k].brith,stu[k].academy,stu[k].score[0],stu[k].score[1],stu[k].score[2],stu[k].score[3],stu[k].average);j=1;}
if(j==0)
{printf("無此人,重新輸入:\n");
goto loop;}
printf("繼續按1,其他數字鍵返回\n");
scanf("%d",&i);
if(i==1)
goto loop;
else goto looq;}
else if(x==2)
{for(k=0;k<o;k++)
for(t=0;t<4;t++)
if(stu[k].score[t]<60)
{printf("學號 姓名 性別 出生日期 系別 第一科 第二科 第三科 第四科 平均\n");
printf("%-6d%-10s%-6s%-13s%-7s%-7.2f%-9.2f%-9.2f%-9.2f%-9.1f\n",stu[k].num,stu[k].name,
stu[k].sex,stu[k].brith,stu[k].academy,stu[k].score[0],stu[k].score[1],stu[k].score[2],stu[k].score[3],stu[k].average);q=1;break;};
if(q==0)
printf("全部及格!\n");
printf ("繼續請按1,其他數字鍵退出:");
scanf ("%d",&k);
if(k==1)
goto looq;};
loow:{};
}

void XG()
{int k,j,t,n,w=-1; float x;
if(m==0)
{printf("請先輸入成績!\n");
goto loop;};
printf("各學生成績:\n");
{printf("學號 姓名 性別 出生日期 系別 第一科 第二科 第三科 第四科 平均\n");
for(k=0;k<o;k++)
printf("%-6d%-10s%-6s%-13s%-7s%-7.2f%-9.2f%-9.2f%-9.2f%-9.1f\n",stu[k].num,stu[k].name,
stu[k].sex,stu[k].brith,stu[k].academy,stu[k].score[0],stu[k].score[1],stu[k].score[2],stu[k].score[3],stu[k].average);}
chucuo:printf ("你要修改的學號:");
scanf("%d",&j);
for(t=0;t<o;t++)
{if (stu[t].num==j)w=t;}
if(w!=-1)
{printf("請輸入你要修改的信息:");
printf("\n修改的學號:\n");
scanf("%d",&stu[w].num);
printf("\n修改的姓名:\n");
scanf("%s",&stu[w].name);
printf ("\n修改的性別:\n");
scanf ("%s",&stu[w].sex);
printf("\n修改的出生日期:\n");
scanf("%s",&stu[w].brith);
printf("\n修改的系別:\n");
scanf("%s",&stu[w].academy);
printf("\n修改的分數:\n");
for(j=0;j<4;j++)
{printf("第%d科",j+1);
scanf("%f",&stu[w].score[j]);}}
x=0;
for(t=0;t<4;t++)
{x=x+stu[w].score[t];}
stu[w].average=x/4;
if (w==-1) {printf("輸入學號有誤,請從新輸入:");goto chucuo;};
printf("修改後各學生成績:\n");
printf("學號 姓名 性別 出生日期 系別 第一科 第二科 第三科 第四科 平均\n");
for(k=0;k<o;k++)
{printf("%-6d%-10s%-6s%-13s%-7s%-7.2f%-9.2f%-9.2f%-9.2f%-9.1f\n",stu[k].num,stu[k].name,
stu[k].sex,stu[k].brith,stu[k].academy,stu[k].score[0],stu[k].score[1],stu[k].score[2],stu[k].score[3],stu[k].average);}
printf("重復修改請按 0,其他數字鍵確認");
scanf("%d",&n);
if(n==0)
XG();
loop:{};}

C. c語言課程設計

字數受限,只能打這多了或看看這個http://wenku..com/view/92d3d138376baf1ffc4fad1a.html#include "stdio.h" #include "stdlib.h" #include "string.h" #include "conio.h" #include "mem.h" #include "ctype.h" /#include "alloc.h" #define N 3 typedef struct z1
{
char no[11];
char name[15];
int score[N];
float sum;
float average;
int order;
struct z1 *next;
}STUDENT;

STUDENT *init();
STUDENT *create();
STUDENT *delete(STUDENT *h);
void print(STUDENT *h); /* 顯示所有記錄*/
void search(STUDENT *h); /*查找*/
void save(STUDENT *h); /*保存*/
STUDENT *load(); /*讀入記錄*/
void computer(STUDENT *h); /*計算總分和均分*/
STUDENT *insert(STUDENT *h); /*插入記錄*/
void append(); /*追加記錄*/
void (); /*復制文件*/
STUDENT *sort(STUDENT *h); /*排序*/
STUDENT *index(STUDENT *h); /*索引*/
void total(STUDENT *h); /*分類合計*/
int menu_select(); /*菜單函數*/
/******主函數開始*******/
main()
{
int i;
STUDENT *head; /*鏈表定義頭指針*/
head=init(); /*初始化鏈表*/
clrscr(); /*清屏*/
for(;;) /*無限循環*/
{
switch(menu_select()) /*調用主菜單函數,返回值整數作開關語句的條件*/
{ /*值不同,執行的函數不同,break 不能省略*/
case 0:head=init();break;
case 1:head=create();break;
case 2:head=delete(head);break;
case 3:print(head);break; /*顯示全部記錄*/
case 4:search(head);break; /*查找記錄*/
case 5:save(head);break; /*保存文件*/
case 6:head=load(); break; /*讀文件*/
case 7:computer(head);break; /*計算總分和均分*/
case 8:head=insert(head); break; /*插入記錄*/
case 9:();break; /*復制文件*/
case 10:head=sort(head);break; /*排序*/
case 11:append();break; /*追加記錄*/
case 12:head=index(head);break; /*索引*/
case 13:total(head);break; /*分類合計*/
case 14:exit(0); /*如菜單返回值為14程序結束*/
}
}
}
/*菜單函數,返回值為整數*/
menu_select()
{
char *menu[]={"***************MENU***************", /*定義菜單字元串數組*/
" 0. init list", /*初始化*/
" 1. Enter list", /*輸入記錄*/
" 2. Delete a record from list", /*從表中刪除記錄*/
" 3. print list ", /*顯示單鏈表中所有記錄*/
" 4. Search record on name", /*按照姓名查找記錄*/
" 5. Save the file", /*將單鏈表中記錄保存到文件中*/
" 6. Load the file", /*從文件中讀入記錄*/
" 7. compute the score", /*計算所有學生的總分和均分*/
" 8. insert record to list ", /*插入記錄到表中*/
" 9. the file to new file", /*復制文件*/
" 10. sort to make new file", /*排序*/
" 11. append record to file", /*追加記錄到文件中*/
" 12. index on nomber", /*索引*/
" 13. total on nomber", /*分類合計*/
" 14. Quit"}; /*退出*/
char s[3]; /*以字元形式保存選擇號*/
int c,i; /*定義整形變數*/
gotoxy(1,25); /*移動游標*/
printf("press any key enter menu......\n"); /*壓任一鍵進入主菜單*/
getch(); /*輸入任一鍵*/
clrscr(); /*清屏幕*/
gotoxy(1,1); /*移動游標*/
textcolor(YELLOW); /*設置文本顯示顏色為黃色*/
textbackground(BLUE); /*設置背景顏色為藍色*/
gotoxy(10,2); /*移動游標*/
putch(0xc9); /*輸出左上角邊框┏*/
for(i=1;i<44;i++)
putch(0xcd); /*輸出上邊框水平線*/
putch(0xbb); /*輸出右上角邊框 ┓*/
for(i=3;i<20;i++)
{
gotoxy(10,i);putch(0xba); /*輸出左垂直線*/
gotoxy(54,i);putch(0xba);
} /*輸出右垂直線*/
gotoxy(10,20);putch(0xc8); /*輸出左上角邊框┗*/
for(i=1;i<44;i++)
putch(0xcd); /*輸出下邊框水平線*/
putch(0xbc); /*輸出右下角邊框┛*/
window(11,3,53,19); /* 製作顯示菜單的窗口,大小根據菜單條數設計*/
clrscr(); /*清屏*/
for(i=0;i<16;i++) /*輸出主菜單數組*/
{
gotoxy(10,i+1);
cprintf("%s",menu[i]);
}
textbackground(BLACK); /*設置背景顏色為黑色*/
window(1,1,80,25); /*恢復原窗口大小*/
gotoxy(10,21); /*移動游標*/
do{
printf("\n Enter you choice(0~14):"); /*在菜單窗口外顯示提示信息*/
scanf("%s",s); /*輸入選擇項*/
c=atoi(s); /*將輸入的字元串轉化為整形數*/
}while(c<0||c>14); /*選擇項不在0~14之間重輸*/
return c; /*返回選擇項,主程序根據該數調用相應的函數*/
}
STUDENT *init()
{
return NULL;
}

/*創建鏈表*/
STUDENT *create()
{
int i; int s;
STUDENT *h=NULL,*info; /* STUDENT指向結構體的指針*/
for(;;)
{
info=(STUDENT *)malloc(sizeof(STUDENT)); /*申請空間*/
if(!info) /*如果指針info為空*/
{
printf("\nout of memory"); /*輸出內存溢出*/
return NULL; /*返回空指針*/
}
inputs("enter no:",info->no,11); /*輸入學號並校驗*/
if(info->no[0]=='@') break; /*如果學號首字元為@則結束輸入*/
inputs("enter name:",info->name,15); /*輸入姓名,並進行校驗*/
printf("please input %d score \n",N); /*提示開始輸入成績*/
s=0; /*計算每個學生的總分,初值為0*/
for(i=0;i<N;i++) /*N門課程循環N次*/
{
do{
printf("score%d:",i+1); /*提示輸入第幾門課程*/
scanf("%d",&info->score[i]);
if(info->score[i]>100||info->score[i]<0)
printf("bad data,repeat input\n");
}while(info->score[i]>100||info->score[i]<0);
s=s+info->score[i];
}
info->sum=s;
info->average=(float)s/N;
info->order=0;
info->next=h;
h=info; }
return(h); /*返回頭指針*/
}
/*輸入字元串,並進行長度驗證*/
inputs(char *prompt, char *s, int count)
{
char p[255];
do{
printf(prompt); /*顯示提示信息*/
scanf("%s",p); if(strlen(p)>count)printf("\n too long! \n"); }while(strlen(p)>count);
strcpy(s,p); }
void print(STUDENT *h)
{
int i=0; /* 統計記錄條數*/
STUDENT *p; /*移動指針*/
clrscr(); /*清屏*/
p=h; /*初值為頭指針*/
printf("\n\n\n****************************STUDENT********************************\n");
printf("|rec|nO | name | sc1| sc2| sc3| sum | ave |order|\n");
printf("|---|----------|---------------|----|----|----|--------|-------|-----|\n");
while(p!=NULL)
{
i++;
printf("|%3d |%-10s|%-15s|%4d|%4d|%4d| %4.2f | %4.2f | %3d |\n", i, p->no,p->name,p->score[0],p->score[1],
p->score[2],p->sum,p->average,p->order);
p=p->next;
}
printf("**********************************end*********************************\n");
}
/*刪除記錄*/
STUDENT *delete(STUDENT *h)
{
STUDENT *p,*q; /*p為查找到要刪除的結點指針,q為其前驅指針*/
char s[11]; /*存放學號*/
clrscr(); /*清屏*/
printf("please deleted no\n"); /*顯示提示信息*/
scanf("%s",s); /*輸入要刪除記錄的學號*/
q=p=h; /*給q和p賦初值頭指針*/
while(strcmp(p->no,s)&&p!=NULL) /*當記錄的學號不是要找的,或指針不為空時*/
{
q=p; /*將p指針值賦給q作為p的前驅指針*/
p=p->next; /*將p指針指向下一條記錄*/
}
if(p==NULL) /*如果p為空,說明鏈表中沒有該結點*/
printf("\nlist no %s student\n",s);
else /*p不為空,顯示找到的記錄信息*/
{
printf("*****************************have found***************************\n");
printf("|no | name | sc1| sc2| sc3| sum | ave |order|\n");
printf("|----------|---------------|----|----|----|--------|-------|-----|\n");
printf("|%-10s|%-15s|%4d|%4d|%4d| %4.2f | %4.2f | %3d |\n", p->no,
p->name,p->score[0],p->score[1],p->score[2],p->sum,
p->average,p->order);
printf("********************************end*******************************\n");
getch(); /*壓任一鍵後,開始刪除*/
if(p==h) /*如果p==h,說明被刪結點是頭結點*/
h=p->next; /*修改頭指針指向下一條記錄*/
else
q->next=p->next; /*不是頭指針,將p的後繼結點作為q的後繼結點*/
free(p); /*釋放p所指結點空間*/
printf("\n have deleted No %s student\n",s);
printf("Don't forget save\n");/*提示刪除後不要忘記保存文件*/
}
return(h); /*返回頭指針*/
}
/*查找記錄*/
void search(STUDENT *h)
{
STUDENT *p; char s[15]; clrscr();
printf("please enter name for search\n");
scanf("%s",s); /*輸入姓名*/
p=h; /*將頭指針賦給p*/
while(strcmp(p->name,s)&&p!=NULL) /*當記錄的姓名不是要找的,或指針不為空時*/
p=p->next; /*移動指針,指向下一結點*/
if(p==NULL) /*如果指針為空*/
printf("\nlist no %s student\n",s); /*顯示沒有該學生*/
else /*顯示找到的記錄信息*/
{
printf("\n\n*****************************havefound***************************\n");
printf("|nO | name | sc1| sc2| sc3| sum | ave |order|\n");
printf("|----------|---------------|----|----|----|--------|-------|-----|\n");
printf("|%-10s|%-15s|%4d|%4d|%4d| %4.2f | %4.2f | %3d |\n", p->no,
p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("********************************end*******************************\n");
}
}
/*插入記錄*/
STUDENT *insert(STUDENT *h)
{
STUDENT *p,*q,*info; /*p指向插入位置,q是其前驅,info指新插入記錄*/
char s[11]; /*保存插入點位置的學號*/
int s1,i;
printf("please enter location before the no\n");
scanf("%s",s); /*輸入插入點學號*/
printf("\nplease new record\n"); /*提示輸入記錄信息*/
info=(STUDENT *)malloc(sizeof(STUDENT)); /*申請空間*/
if(!info)
{
printf("\nout of memory"); /*如沒有申請到,內存溢出*/
return NULL; /*返回空指針*/
}
inputs("enter no:",info->no,11); /*輸入學號*/
inputs("enter name:",info->name,15); /*輸入姓名*/
printf("please input %d score \n",N); /*提示輸入分數*/
s1=0; /*保存新記錄的總分,初值為0*/
for(i=0;i<N;i++) /*N門課程循環N次輸入成績*/
{
do{ /*對數據進行驗證,保證在0~100之間*/
printf("score%d:",i+1);
scanf("%d",&info->score[i]);
if(info->score[i]>100||info->score[i]<0)
printf("bad data,repeat input\n");
}while(info->score[i]>100||info->score[i]<0);
s1=s1+info->score[i]; /*計算總分*/
}
info->sum=s1; /*將總分存入新記錄中*/
info->average=(float)s1/N; /*計算均分*/
info->order=0; /*名次賦值0*/
info->next=NULL; /*設後繼指針為空*/
p=h; /*將指針賦值給p*/
q=h; /*將指針賦值給q*/
while(strcmp(p->no,s)&&p!=NULL) /*查找插入位置*/
{
q=p; /*保存指針p,作為下一個p的前驅*/
p=p->next; /*將指針p後移*/
}
if(p==NULL) /*如果p指針為空,說明沒有指定結點*/
if(p==h) /*同時p等於h,說明鏈表為空*/
h=info; /*新記錄則為頭結點*/
else
q->next=info; else
if(p==h) {
info->next=p; h=info; }
else
{
info->next=p; q->next=info;
}
printf("\n ----have inserted %s student----\n",info->name); printf("---Don't forget save---\n"); /*提示存檔*/
return(h); /*返回頭指針*/
}
/*保存數據到文件*/
void save(STUDENT *h)
{
FILE *fp; /*定義指向文件的指針*/
STUDENT *p; /* 定義移動指針*/
char outfile[10]; /*保存輸出文件名*/
printf("Enter outfile name,for example c:\\f1\\te.txt:\n"); /*提示文件名格式信息*/
scanf("%s",outfile);
if((fp=fopen(outfile,"wb"))==NULL) /*為輸出打開一個二進制文件,如沒有則建立*/
{
printf("can not open file\n");
exit(1);
}
printf("\nSaving file......\n"); /*打開文件,提示正在保存*/
p=h; /*移動指針從頭指針開始*/
while(p!=NULL) /*如p不為空*/
{
fwrite(p,sizeof(STUDENT),1,fp);/*寫入一條記錄*/
p=p->next; /*指針後移*/
}
fclose(fp); /*關閉文件*/
printf("-----save success!!-----\n"); /*顯示保存成功*/
}
/* 從文件讀數據*/
STUDENT *load()
{
STUDENT *p,*q,*h=NULL; /*定義記錄指針變數*/
FILE *fp; /* 定義指向文件的指針*/
char infile[10]; /*保存文件名*/
printf("Enter infile name,for example c:\\f1\\te.txt:\n"); scanf("%s",infile); /*輸入文件名*/
if((fp=fopen(infile,"rb"))==NULL) /*打開一個二進制文件,為讀方式*/
{
printf("can not open file\n"); /*如不能打開,則結束程序*/
exit(1);
}
printf("\n -----Loading file!-----\n");
p=(STUDENT *)malloc(sizeof(STUDENT)); /*申請空間*/
if(!p)
{
printf("out of memory!\n"); /*如沒有申請到,則內存溢出*/
return h; /*返回空頭指針*/
}
h=p; /*申請到空間,將其作為頭指針*/
while(!feof(fp)) /*循環讀數據直到文件尾結束*/
{
if(1!=fread(p,sizeof(STUDENT),1,fp))
break; /*如果沒讀到數據,跳出循環*/
p->next=(STUDENT *)malloc(sizeof(STUDENT)); /*為下一個結點申請空間*/
if(!p->next)
{
printf("out of memory!\n"); return h;
}
q=p; p=p->next; }
q->next=NULL; /*最後一個結點的後繼指針為空*/
fclose(fp); /*關閉文件*/
printf("---You have success read data from file!!!---\n");
return h; /*返回頭指針*/
}
/*追加記錄到文件*/
void append()
{
FILE *fp; /*定義指向文件的指針*/
STUDENT *info; /*新記錄指針*/
int s1,i;
char infile[10]; /*保存文件名*/
printf("\nplease new record\n");
info=(STUDENT *)malloc(sizeof(STUDENT)); /*申請空間*/
if(!info)
{
printf("\nout of memory"); /*沒有申請到,內存溢出本函數結束*/
return ;
}
inputs("enter no:",info->no,11); /*調用inputs輸入學號*/
inputs("enter name:",info->name,15); /*調用inputs輸入姓名*/
printf("please input %d score \n",N); /*提示輸入成績*/
s1=0;
for(i=0;i<N;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&info->score[i]); /*輸入成績*/
if(info->score[i]>100||info->score[i]<0)printf("bad data,repeat input\n");
}while(info->score[i]>100||info->score[i]<0); /*成績數據驗證*/
s1=s1+info->score[i]; /*求總分*/
}
info->sum=s1; /*保存總分*/
info->average=(float)s1/N; /*求均分*/
info->order=0; /*名次初始值為0*/
info->next=NULL; /*將新記錄後繼指針賦值為空*/
printf("Enter infile name,for example c:\\f1\\te.txt:\n"); scanf("%s",infile); /*輸入文件名*/
if((fp=fopen(infile,"ab"))==NULL) /*向二進制文件尾增加數據方式打開文件*/
{
printf("can not open file\n"); /*顯示不能打開*/
exit(1); /*退出程序*/
}
printf("\n -----Appending record!-----\n");
if(1!=fwrite(info,sizeof(STUDENT),1,fp)) /*寫文件操作*/
{
printf("-----file write error!-----\n");
return; /*返回*/
}
printf("-----append sucess!!----\n");
fclose(fp); /*關閉文件*/
}
/*文件拷貝*/
void ()
{
char outfile[10],infile[10];
FILE *sfp,*tfp; /*源和目標文件指針*/
STUDENT *p=NULL; /*移動指針*/
clrscr(); /*清屏*/
printf("Enter infile name,for example c:\\f1\\te.txt:\n");
scanf("%s",infile); /*輸入源文件名*/
if((sfp=fopen(infile,"rb"))==NULL) /*二進制讀方式打開源文件*/
{
printf("can not open input file\n");
exit(0);
}
printf("Enter outfile name,for example c:\\f1\\te.txt:\n"); /*提示輸入目標文件名*/
scanf("%s",outfile); /*輸入目標文件名*/
if((tfp=fopen(outfile,"wb"))==NULL) /*二進制寫方式打開目標文件*/
{
printf("can not open output file \n");
exit(0);
}
while(!feof(sfp)) /*讀文件直到文件尾*/
{
if(1!=fread(p,sizeof(STUDENT),1,sfp))
break; /*塊讀*/
fwrite(p,sizeof(STUDENT),1,tfp); /*塊寫*/
}
fclose(sfp); /*關閉源文件*/
fclose(tfp); /*關閉目標文件*/
printf("you have success file!!!\n"); /*顯示成功拷貝*/
}
/*排序*/
STUDENT *sort(STUDENT *h)
{
int i=0; /*保存名次*/
STUDENT *p,*q,*t,*h1; /*定義臨時指針*/
h1=h->next; /*將原表的頭指針所指的下一個結點作頭指針*/
h->next=NULL; /*第一個結點為新表的頭結點*/
while(h1!=NULL) /*當原表不為空時,進行排序*/
{
t=h1; /*取原表的頭結點*/
h1=h1->next; /*原表頭結點指針後移*/
p=h; /*設定移動指針p,從頭指針開始*/
q=h; /*設定移動指針q做為p的前驅,初值為頭指針*/
while(t->sum<p->sum&&p!=NULL) /*作總分比較*/
{
q=p; /*待排序點值小,則新表指針後移*/
p=p->next;
}
if(p==q) /*p==q,說明待排序點值大,應排在首位*/
{
t->next=p; /*待排序點的後繼為p*/
h=t; /*新頭結點為待排序點*/
}
else /*待排序點應插入在中間某個位置q和p之間,如p為空則是尾部*/
{
t->next=p; /*t的後繼是p*/
q->next=t; /*q的後繼是t*/
}
}
p=h; /*已排好序的頭指針賦給p,准備填寫名次*/
while(p!=NULL) /*當p不為空時,進行下列操作*/
{
i++; /*結點序號*/
p->order=i; /*將名次賦值*/
p=p->next; /*指針後移*/
}
printf("sort sucess!!!\n"); /*排序成功*/
return h; /*返回頭指針*/
}
/*計算總分和均值*/
void computer(STUDENT *h)
{
STUDENT *p; /*定義移動指針*/
int i=0; /*保存記錄條數初值為0*/
long s=0; /*總分初值為0*/
float average=0; /*均分初值為0*/
p=h; /*從頭指針開始*/
while(p!=NULL) /*當p不為空時處理*/
{
s+=p->sum; /*累加總分*/
i++; /*統計記錄條數*/
p=p->next; /*指針後移*/
}
average=(float)s/i;/* 求均分,均分為浮點數,總分為整數,所以做類型轉換*/
printf("\n--All students sum score is:%ld average is %5.2f\n",s,average);
}
/*索引*/
STUDENT *index(STUDENT *h)
{
STUDENT *p,*q,*t,*h1; /*定義臨時指針*/
h1=h->next; /*將原表的頭指針所指的下一個結點作頭指針*/
h->next=NULL; /*第一個結點為新表的頭結點*/
while(h1!=NULL) /*當原表不為空時,進行排序*/
{
t=h1; /*取原表的頭結點*/
h1=h1->next; /*原表頭結點指針後移*/
p=h; /*設定移動指針p,從頭指針開始*/
q=h; /*設定移動指針q做為p的前驅,初值為頭指針*/
while(strcmp(t->no,p->no)>0&&p!=NULL) /*作學號比較*/
{
q=p; p=p->next;
}
if(p==q) /*p==q, {
t->next=p; h=t; }
else {
t->next=p; /*t的後繼是p*/
q->next=t; /*q的後繼是t*/
}
}
printf("index sucess!!!\n"); /*索引排序成功*/
return h; /*返回頭指針*/
}
/*分類合計*/
void total(STUDENT *h)
{
STUDENT *p,*q; /*定義臨時指針變數*/
char sno[9],qno[9],*ptr; /*保存班級號的*/
float s1,ave; /*保存總分和均分*/
int i; clrscr(); /*清屏*/
printf("\n\n *******************Total*****************\n");
printf("---class---------sum--------------average----\n");
p=h; while(p!=NULL)
{
memcpy(sno,p->no,8); /*從學號中取出班級號*/
sno[8]='\0'; /*做字元串結束標記*/
q=p->next; /*將指針指向待比較的記錄*/
s1=p->sum; /*當前班級的總分初值為該班級的第一條記錄總分*/
ave=p->average; /*當前班級的均分初值為該班級的第一條記錄均分*/
i=1; /*統計當前班級人數*/
while(q!=NULL) /*內循環開始*/
{
memcpy(qno,q->no,8); /*讀取班級號*/
qno[8]='\0'; /*做字元串結束標記*/
if(strcmp(qno,sno)==0) /*比較班級號*/
{
s1+=q->sum; /*累加總分*/
ave+=q->average; /*累加均分*/
i++; /*累加班級人數*/
q=q->next; /*指針指向下一條記錄*/
}
else
break; }
printf("%s %10.2f %5.2f\n",sno,s1,ave/i);
if(q==NULL)
break; else
p=q; }
printf("---------------------------------------------\n");
}


D. C語言程序課程設計

#include <stdio.h>
#define MAX 200
int main()
{
int a[MAX][MAX],n;
void initmatrix(int a[][MAX]);//初始化矩陣,將所有元素賦0
void creatematrix_2k1(int a[][MAX],int n);//生成2n+1階幻方
void creatematrix_4k(int a[][MAX],int n);//生成4n階幻方
void creatematrix_4k2(int a[][MAX],int n);//生成4n+2階幻方
void outputmatrix(int a[][MAX],int n);//輸出n階幻方
initmatrix(a);
printf("please input a interger number:");
scanf("%d",&n);
if(n%2) creatematrix_2k1(a,(n-1)/2);
else {if(n%4==0) creatematrix_4k(a,n/4);
else creatematrix_4k2(a,(n-2)/4);}
outputmatrix(a,n);
return 0;
}
void initmatrix(int a[][MAX])
{
for(int i=0;i<MAX;i++)
for(int j=0;j<MAX;j++)
a[i][j]=0;
}
void outputmatrix(int a[][MAX],int n)
{
for(int i=0;i<n;i++)
{
printf("第%-3d行的數依次為:",i+1);
for(int j=0;j<n;j++)
printf("%-5d",a[i][j]);
printf("\n");
}
}
void creatematrix_2k1(int a[][MAX],int n)
{
int col=-1,row=-1;
int *p,*q;
p=&col,q=&row;
void fillmatrix(int a[][MAX],int *p,int *q,int n,int i);//將i填入2n+1階幻方中
for(int i=1;i<=((2*n+1)*(2*n+1));i++)
fillmatrix(a,p,q,n,i);
}
void fillmatrix(int a[][MAX],int *p,int *q,int n,int i)
{
if(i==1)
{
a[0][n]=i;
*p=0,*q=n;
}

else
{
if((*p==0&&*q==2*n)||a[(*p+2*n)%(2*n+1)][(*q+1)%(2*n+1)])
{
a[(*p+1)%(2*n+1)][*q]=i;
*p=(*p+1)%(2*n+1);}
else{a[(*p+2*n)%(2*n+1)][(*q+1)%(2*n+1)]=i;
*p=(*p+2*n)%(2*n+1),*q=(*q+1)%(2*n+1);}
}
}
void creatematrix_4k(int a[][MAX],int n)
{
int temp;
for(int i=0;i<4*n;i++)
{ for(int j=0;j<4*n;j++)
a[i][j]=4*n*i+j+1;}
for(i=0;i<4*n;i++)
for(int j=0;j<4*n;j++)
if((i>j)&&((i-j)%4==0||(i+j+1)%4==0))
{temp=a[i][j];
a[i][j]=a[4*n-1-i][4*n-1-j];
a[4*n-1-i][4*n-1-j]=temp;}
for(i=0;i<2*n;i++)
{temp=a[i][i];
a[i][i]=a[4*n-1-i][4*n-1-i];
a[4*n-1-i][4*n-1-i]=temp;}
}
void creatematrix_4k2(int a[][MAX],int n)//構造4n+2階幻方
{
int col=-1,row=-1,i;
int exn=(2*n+1)*(2*n+1);
int *p,*q;
p=&col,q=&row;
void fillmatrix_2(int a[][MAX],int *p,int *q,int cs, int rs,int n,int i);/*將i填入以a[cs][rs]為起始的2n+1階幻方中,用p,q返回的i-1行列值*/
for(i=1;i<=exn;i++)
fillmatrix_2(a,p,q,0,0,n,i);
for(i=exn+1;i<=exn*2;i++)
fillmatrix_2(a,p,q,2*n+1,2*n+1,n,i);
for(i=2*exn+1;i<=3*exn;i++)
fillmatrix_2(a,p,q,0,2*n+1,n,i);
for(i=3*exn+1;i<=4*exn;i++)
fillmatrix_2(a,p,q,2*n+1,0,n,i);
void lastswap(int a[][MAX],int n);//對4n+2階幻方做最後的變換
lastswap(a,n);
}
void fillmatrix_2(int a[][MAX],int *p,int *q,int cs, int rs,int n,int i)
{
int exn=(2*n+1)*(2*n+1);
if(i%exn==1)
{
a[cs+0][rs+n]=i;
*p=0,*q=n;
}

else {if((*p==0&&*q==2*n)||a[(*p+2*n)%(2*n+1)+cs][(*q+1)%(2*n+1)+rs])
{
a[(*p+1)%(2*n+1)+cs][*q+rs]=i;
*p=(*p+1)%(2*n+1);
}
else{
a[(*p+2*n)%(2*n+1)+cs][(*q+1)%(2*n+1)+rs]=i;
*p=(*p+2*n)%(2*n+1),*q=(*q+1)%(2*n+1);
}
}
}
void lastswap(int a[][MAX],int n)
{
int temp,i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{temp=a[i][j];
a[i][j]=a[2*n+1+i][j];
a[2*n+1+i][j]=temp;}
for(i=1;i<=n;i++)
{temp=a[n][i];
a[n][i]=a[3*n+1][i];
a[3*n+1][i]=temp;}
for(i=n+1;i<2*n+1;i++)
for(j=0;j<n;j++)
{temp=a[i][j];
a[i][j]=a[2*n+1+i][j];
a[2*n+1+i][j]=temp;}
for(i=0;i<2*n+1;i++)
for(j=4*n+1;j>3*n+2;j--)
{temp=a[i][j];
a[i][j]=a[2*n+1+i][j];
a[2*n+1+i][j]=temp;}
}
求幻方的程序

#include <stdio.h>
#include <stdlib.h>
#define IO "%d"//和下面一行共同擴展數據成員的格式
typedef int ElemType;//同上
typedef struct LinkNode
{
ElemType data;
struct LinkNode *next;
}LinkNode,*Link;
Link creat();//建立帶頭結點的鏈表,並返回頭指針
void print(Link);//輸出鏈表所有結點
bool insert(Link,int ,ElemType);//向head為頭指針的鏈表中插入元素e使之成為鏈表第i個元素成功返回TRUE否則FALSE
bool del(Link,int );//在head為頭指針的鏈表中刪除第i個結點,成功返回TRUE否則返回FALSE
void operate(Link);//在本程序中進行鏈表的插入,刪除,輸出操作
Link creat()
{
Link head=(Link)malloc(sizeof(LinkNode));
Link pre=head,p;
int count=1;
char ch;
printf("是否終止建立鏈表(Y/N):");
scanf("%c",&ch);
while(ch=='n'||ch=='N')
{
p=(Link)malloc(sizeof(LinkNode));
printf("請輸入第%d個結點內的數據:",count);
scanf(IO,&(p->data));
fflush(stdin);
pre->next=p;
pre=p;
printf("是否終止建立鏈表(Y/N):");
scanf("%c",&ch);
count++;
}
pre->next=NULL;
return head;
}
void print(Link head)
{
printf("鏈表目前情況為:\n");
Link p=head->next;
int count=1;
while(p)
{
printf("第%d個結點中數據為"IO" ",count,p->data);
p=p->next;
if((count++)%3==0)printf("\n");
}
if(count%3!=1)printf("\n");
}
bool insert(Link head,int i,ElemType e)
{
Link pre,p;
int k;
for(k=0,pre=head;k<i-1&⪯k++,pre=pre->next);//尋找第i-1個元素的指針
if(k!=i-1||(!pre))return false;
p=(Link)malloc(sizeof(LinkNode));
p->data=e;
p->next=pre->next;
pre->next=p;
return true;
}
bool del(Link head,int i)
{ Link pre,p;
int k;
for(k=0,pre=head,p=head->next;k<i-1&&p;k++,pre=p,p=p->next);//尋找第i-1個元素的指針
if(k!=i-1||(!p))return false;
pre->next=p->next;
free(p);
return true;
}
void operate(Link head)
{
int n,i;
ElemType e;
do
{
printf("************************************************\n");
printf("請輸入想進行何種操作\n1============插入結點\n2============刪除結點\n3============輸出鏈表\n");
scanf("%d",&n);
switch(n)
{
case 1:printf("現在進行結點插入\n");
printf("請輸入欲插入到何位置:");scanf("%d",&i);
printf("請輸入欲插入的數據:");scanf(IO,&e);
if(insert(head,i,e))printf("插入成功!\n");else printf("插入失敗!\n");
break;
case 2:printf("現在進行結點刪除\n");
printf("請輸入欲刪除結點位置:");scanf("%d",&i);
if(del(head,i))printf("刪除成功!\n");else printf("刪除失敗!\n");
break;
case 3:print(head);break;
default:break;
}
}while(n<4&&n>0);
}
int main()
{
Link head=creat();
operate(head);
return 0;
}
鏈表的操作

#include <stdio.h>
#include <math.h>//求積分
int main()
{
double f1(double);
double f2(double);
double f3(double);
double f4(double);
double f5(double);
double (*p)(double);
double integral(double a,double b,double(*p)(double));
double a,b;//記錄積分區間
printf("請輸入積分區間:");
scanf("%lf %lf",&a,&b);
if(a>b){double temp=a;a=b;b=temp;}//確保a<b
printf("sin(x)在[%lf,%lf]上的積分值為%lf\n",a,b,integral(a,b,sin));
printf("cos(x)在[%lf,%lf]上的積分值為%lf\n",a,b,integral(a,b,cos));
printf("exp(x)在[%lf,%lf]上的積分值為%lf\n",a,b,integral(a,b,exp));
printf("x+1在[%lf,%lf]上的積分值為%lf\n",a,b,integral(a,b,f1));
printf("2x+3在[%lf,%lf]上的積分值為%lf\n",a,b,integral(a,b,f2));
printf("exp(x)+1在[%lf,%lf]上的積分值為%lf\n",a,b,integral(a,b,f3));
printf("(1+x)^2在[%lf,%lf]上的積分值為%lf\n",a,b,integral(a,b,f4));
printf("x^3在[%lf,%lf]上的積分值為%lf\n",a,b,integral(a,b,f5));
return 0;
}
double integral(double a,double b,double(*p)(double))
{
double sum=0,l=b-a,pl;//sum保存積分和,l保存積分區間的長度,pl保存積分區間細分後每個小區間的長度
int n=2,i;//n保存劃分的小區間數i用作累加指針
pl=l/n;
while(pl>1e-6)
{
sum=0;
for(i=0;i<n;i++)
sum+=(*p)(a+i*pl)*pl;
n*=2;
pl/=2;
}
return sum;
}
double f1(double x)
{
return x+1;
}
double f2(double x)
{
return 2*x+3;
}
double f3(double x)
{
return exp(x)+1;
}
double f4(double x)
{
return (1+x)*(1+x);
}
double f5(double x)
{
return x*x*x;
}

求積分

都是以前寫的 便宜樓主了!!

E. 《C語言程序設計》課程設計

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>

#define BUFFERSIZE 1024
#define MAXACCOUNT 1000
typedef struct BankAccount
{
int account;
int key;
char name[32];
float balance;
}BANKACCOUNT;

BANKACCOUNT accountCollection[MAXACCOUNT];
int curAccount = 0;

void InsertAccount(FILE *fp)
{
BANKACCOUNT newaccount;
printf("please input the account information\n");
printf(">>account num:");
scanf("%d",&(newaccount.account));
printf(">>key:");
scanf("%d",&(newaccount.key));
printf(">>name:");
scanf("%s",newaccount.name);
printf(">>balance:");
scanf("%f",&(newaccount.balance));
fseek(fp,0L,SEEK_END);
fprintf(fp,"%d %d %s %.2f\n",newaccount.account,newaccount.key,newaccount.name,newaccount.balance);
}
void GetAccount(FILE *fp)
{
int accountnum;
int key;
char name[32];
float balance;
int i =0,j;
char buffer[BUFFERSIZE];
int len;
curAccount = 0;
fseek(fp,0,SEEK_SET);
while(!feof(fp)) /* 因為feof()最後會讀2遍,所以最後curAccount多加了1 */
{
fscanf(fp,"%d %d %s %f",&accountnum,&key,name,&balance);
accountCollection[curAccount].account = accountnum;
accountCollection[curAccount].key = key;
strcpy(accountCollection[curAccount].name ,name);
accountCollection[curAccount].balance = balance;
curAccount++;
}
}
void ListAccount(FILE *fp)
{
int i =0;
printf("There is %d accounts at all:\n",curAccount-1);/* curAccount減去多加的1 */
for(i = 0;i< curAccount-1;i++)
{
printf("ACCOUNT[%d]:\n",i+1);
printf("account:%d\n",accountCollection[i].account);
printf("name:%s\n",accountCollection[i].name);
printf("balance:%.2f\n",accountCollection[i].balance);
}
}
int SearchAccount(FILE *fp,int accountnum)
{
int i =0;
for(i = 0;i< curAccount-1;i++)
{
if(accountCollection[i].account == accountnum)
{
printf("ACCOUNT[%d]:\n",i+1);
printf("account:%d\n",accountCollection[i].account);
printf("name:%s\n",accountCollection[i].name);
printf("balance:%.2f\n",accountCollection[i].balance);
return 1;
}
}
return 0;
}
void DelAccount(FILE *fp,int accountnum)
{
int i;
if(SearchAccount(fp,accountnum)==0)
printf("Can't find the account\n");
else
{
for(i = 0;i<curAccount-1;i++)
{
if(accountCollection[i].account != accountnum)
fprintf(fp,"%d %d %s %.2f\n",accountCollection[i].account,accountCollection[i].key,accountCollection[i].name,accountCollection[i].balance);
}
printf("delete successfully!\n");
}
}

int main()
{
FILE *fp;
int accountnum;
int i;
do{
system("cls"); //清屏
puts("********************************************");
puts("* You can choose : *");
puts("* 1 : Insert a new Account *");
puts("* 2 : List all Accounts *");
puts("* 3 : Find a Account *");
puts("* 4 : Delete a Account *");
puts("* 5 : quit *");
puts("********************************************");
printf("Please input your choice:");
scanf("%d",&i);
system("cls"); //清屏
switch(i)
{
case 1:
if(!(fp = fopen("account.txt","a+")))
{
printf("can't open the file account.txt\n");
exit(0);
}
InsertAccount( fp);

printf("press any key to continue.....\n");
getch();
fclose(fp);
break;
case 2:
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
ListAccount(fp);

fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
case 3:
printf("please input the account num:\n");
scanf("%d",&accountnum);
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
if(!SearchAccount(fp,accountnum))
printf("There is not the account:%d\n",accountnum);

fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
case 4:
printf("please input the account num:\n");
scanf("%d",&accountnum);
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
fclose(fp);
if(!(fp = fopen("account.txt","w+")))
{
printf("can't open the file account.txt\n");
exit(0);
}
DelAccount(fp,accountnum);
fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
default:
break;
}
}while(i != 5);
return 0;
}
賬戶數據文件名已經設定為account.txt,這個文件要和上面這個程序放在同一個文件夾下面,不然就得用絕對路徑(比如"d:\\book\\account.txt"),account內容可以用記事本打開自己改動,然後運行程序後就可以在程序中添加或刪除

F. c語言程序課程設計

給你代碼,你自己去研究吧
#include <stdio.h>
#define SIZE 10

typedef struct student
{
int num;
char name[20];
int score[3];
float average;
}student;

void indata(student *stu)
{
int i;

for (i = 0; i < SIZE; i++)
{
scanf("%d %s %d %d %d%*c", &stu[i].num, stu[i].name, &stu[i].score[0],
&stu[i].score[1], &stu[i].score[2]);
}
}

void outdata(student *stu)
{
int i;

for (i = 0; i < SIZE; i++)
{
printf("%d %s %d %d %d %f\n", stu[i].num, stu[i].name, stu[i].score[0],
stu[i].score[1], stu[i].score[2], stu[i].average);
}
}

int main()
{
student stu[SIZE];
int i, j;
int t;
student temp;

printf("請輸入信息:\n");
indata(stu);

for (i = 0; i < SIZE; i++) //算平均分
{
stu[i].average = 0;
for (j = 0; j < 3; j++)
stu[i].average += stu[i].score[j];
stu[i].average /= 3;
}

for (i = 0; i < SIZE - 1; i++) //按平均分進行排序
{
t = i;
for (j = i + 1; j < SIZE; j++)
{
if (stu[t].average > stu[j].average)
t = j;
}
if (t == i)
continue;
else
{
temp = stu[i];
stu[i] = stu[t];
stu[t] = temp;
}
}

printf("排序後信息為:\n");
outdata(stu);

return 0;
}

G. C語言課程設計難嗎C語言這門課難還是課程設計難

c語言課程設計不難。但是看問題人好像沒有學過C語言,那對你來說就難了。因為雖然C語言是一門很基礎的課程,但是想要突擊學會還是不太現實的,編程是需要一段代碼一段代碼敲出來,才會有實力提升的,很難突擊出來。所以如果沒學過C語言,C語言的課程設計難。
如果已經學習過了C語言,有了底子之後就不難了。原因有三:一:如果C語言底子不好的話,就去網路。C語言課程設計的題目都被大學生做爛了,網上到處是源代碼。老師出的題就算找不到元題,也能找到類似的題,照貓畫虎,就能夠交差了。二,C語言課程設計是把前面的知識綜合運用。如果C語言底子好,平時練習多,那麼只要能夠做到把課程設計題目細化為一個一個模塊----函數,然後再把一個一個函數編輯出來,最後函數嵌套函數,一個課程設計就出來了。比如選課系統的設計。三:課程設計是個活的東西,底子好的人,你可以再原有程序加上很多內容,大大擴充自己的程序功能;一些不愛編程的人,完成基本功能也不難。所以不管怎麼樣,作業做出來還是簡單的。
例如選課系統的設計
查看所有課程-------顯示所有課程的函數。用數組,或者結構題,加上printf語句可以完成,這部分比較簡單。
查詢課程------查詢函數。根據關鍵字來查詢,也不難,如果用數組名來查詢,只需要把全部課程的名字與查詢課程對比就像。
選課-----選課函數。在儲存有學生課程的數組中,在最後再加一個數組元素就可以了。
刪除已選課程----刪課函數。和添加差不多。
顯示自己已選函數。----和現實所有課程差不多。
還有寫入寫出函數-----這個是不常用的東西,把一些信息在開始寫入我們的程序中,在最後把我們修改的信息儲存起來。
,,,,,,,
大體上一個簡單的選課系統就成了。完成這個程度,如果學習了C語言,應該是不難的。當然,這個程序還有很多的可以提升的地方,只要發揮自己的想像力,去動手,完善自覺地程序,做出來一份報告是不難的,不斷的改進,做出來一份拿出手的程序,也不是不可能的。
總結,C語言簡單,但是不可突擊。課程設計不難,想要做出一個好的課程設計作業出來,需要花點心思。
本人也不是什麼高手,只是粗談下自己的意見。

H. C語言課程設計與C語言程序設計有什麼區別

程序設計是簡單的小程序~一般幾十行代碼就可以實現~例如計算前n項和~
課程設計是大的程序設計~一般都要百行代碼才能實現~~~例如游樂園售票系統~只給了一個大的概念~~
反正總的來說就是課程設計是較難的程序設計~~

熱點內容
工業伺服器機箱怎麼樣 發布:2025-02-14 00:29:15 瀏覽:85
英朗壓縮機 發布:2025-02-14 00:29:12 瀏覽:677
java門面模式 發布:2025-02-14 00:29:09 瀏覽:916
java旋轉 發布:2025-02-14 00:22:49 瀏覽:103
存儲虛擬化方案 發布:2025-02-14 00:21:15 瀏覽:695
ubuntupython3安裝 發布:2025-02-14 00:14:45 瀏覽:661
和平精英怎麼更新比較快安卓 發布:2025-02-14 00:14:35 瀏覽:974
怎麼改密碼鎖 發布:2025-02-13 23:47:39 瀏覽:852
androidbitmap獲取大小 發布:2025-02-13 23:47:38 瀏覽:559
怎麼把升級鴻蒙系統變回安卓 發布:2025-02-13 23:36:07 瀏覽:595