當前位置:首頁 » 編程語言 » c語言系統代碼

c語言系統代碼

發布時間: 2023-08-18 04:15:50

『壹』 最簡單的c語言代碼

最簡單的C語言代就是輸出「helloWord」,通常是作為初學編程語言時的第一個程序代碼。具體代碼如下:

#include <stdio.h>

int main(){

printf("Hello, World! ");

return 0;

}

(1)c語言系統代碼擴展閱讀:

1、程序的第一行#include <stdio.h>是預處理器指令,告訴 C 編譯器在實際編譯之前要包含 stdio.h 文件。

2、下一行intmain()是主函數,程序從這里開始執行。

3、下一行printf(...)是C中另一個可用的函數,會在屏幕上顯示消息"Hello,World!"。

4、下一行return0;終止main()函數,並返回值0。

『貳』 C語言學生成績管理系統代碼

typedef struct student{
char name[MAX];
int num[MAX];
char sex[MAX];
int chinese;
int mathematic;
int english;
int computer;
struct student *next;
}

程序代碼:
//原始密碼是123456
#include"stdio.h"
#include"stddef.h"
#include"stddef.h"
#include"string.h"
#define MAX 10
typedef struct student{ /*定義結構體*/
char name[MAX]; /*姓名*/
int num[MAX]; /* 學號*/
char sex[MAX]; /*性別*/
int chinese; /*語文*/
int mathematic; /* 數學*/
int english; /*英語*/
int computer; /*計算機*/
struct student *next; /*結構體指針*/
}stu;
stu *head; /*頭指針*/
void print() /*顯示或列印函數*/
{
system("cls");
printf("\t\t\tScore Manage System\n"); /*成績管理系統*/
printf("<1>Enter Record\t"); /*輸入數據*/
printf("<2>Display\t"); /*顯示*/
printf("<3>Insert\t"); /*插入數據*/
printf("<4>Quest\t"); /*訪問數據*/
printf("<5>Update\t"); /*以前數據*/
printf("<6>Save\t"); /*保留數據*/
printf("<7>Fresh\t"); /*更新數據*/
printf("<8>Chinese Average\t"); /*語文平均成績*/
printf("<9>Math Average\t"); /*數學平均成績*/
printf("<10>English Average\t"); /*英語平均成績*/
printf("<11>Computer Average\t"); /*計算機平均成績*/
printf("<12>Quit\t\n"); /*退出*/
}

void cin(stu *p1) /*輸入相關數據的函數*/
{ printf("Enter name:\n");
scanf("%s",&p1->name);
printf("Enter num:\n");
scanf("%d",&p1->num);
printf("Enter sex:\n");
scanf("%s",&p1->sex);
printf("Enter score:\n");
printf("Enter chinese:\n");
scanf("%d",&p1->chinese);
printf("Enter math:\n");
scanf("%d",&p1->mathematic);
printf("Enter English:\n");
scanf("%d",&p1->english);
printf("Enter Computer:\n");
scanf("%d",&p1->computer);
}
stu *cindata() /*其他數據是否繼續輸入的函數*/
{ stu *p1,*p2;
int i=1;
char ch;
p1=(stu *)malloc(sizeof(stu));
head=p1;
while(i)
{
cin(p1);
printf("Do you Want to Continue?yes or no"); /*是否繼續輸入數據*/
ch=getchar();
ch=getchar();
if(ch=='n'||ch=='N')
{ i=0;
p1->next=NULL;
}
else
{ p2=p1;
p1=(stu *)malloc(sizeof(stu));
p2->next=p1;
}
}
return(p1->next);
}

stu *lookdata(stu *p1) /*查看數據的函數*/
{
while(p1!=NULL)
{ printf("Num:%d\t",p1->num);
printf("Name:%s\t",p1->name);
printf("Sex:%s\t",p1->sex);
printf("\n");
printf("Chinese:%d\t",p1->chinese);
printf("Math:%d\t",p1->mathematic);
printf("English:%d\t",p1->english);
printf("Computer:%d\t",p1->computer);
printf("\n");
p1=p1->next;
}
return p1;
}

void insert() /*通過比較學號來插入數據的函數*/
{ stu *p1,*p3,*p2;
char ch;
p1=head;
p3=(stu *)malloc(sizeof(stu));

p3->next=NULL;
if(head==NULL){ head=p3; return;}
cin(p3);
while(p1!=NULL&&(p1->num<p3->num)) /*通過學號的比較來插入*/
{ p2=p1;p1=p1->next;}
if(p2==head) {p3->next=head; head=p3; return;}
p3->next=p1;
p2->next=p3;

}

find(stu *p2) /*通過姓名查找查看數據的函數*/
{ char name[20];
int b=0;
printf("Enter the name of the student you want to find:"); /*通過姓名查看*/
scanf("%s",name);
while(p2!=NULL)
{if(strcmp(name,p2->name)==0)
{
printf("The data you want has be found\n");
printf(" Name:%s\t",p2->name);
printf("Num:%d\t",p2->num);
printf("sex%s\t",p2->sex);
printf("\n");
printf("Chinese:%d\t",p2->chinese);
printf("Math:%d\t",p2->mathematic);
printf("English:%d\t",p2->english);
printf("Computer:%d\t",p2->computer);
printf("\n");

b=1;
}
else if(b==0)
printf("sorry not find data!");
p2=p2->next;
}

if(b==1)
{
print();
printf("Find one\n");}
else
{print();
printf("Not find\n");

}
}

void caverage() /*求各學生語文平均分、最高和最低分成績的函數*/
{ stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->chinese;
aver=sum/i;

p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{if(max<p1->chinese)
max=p1->chinese;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->chinese)
min=p1->chinese;
}
printf("Chinese Average:%f",aver);
printf("Chinese Max:%f",max);
printf("Chinese Min:%f",min);
}

void maverage() /*求各學生數學平均分、最高和最低分成績的函數*/
{ stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->mathematic;
aver=sum/i;

p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{if(max<p1->mathematic)
max=p1->mathematic;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->mathematic)
min=p1->mathematic;
}
printf("Mathe Average:%f",aver);
printf("Mathe Max:%f",max);
printf("Mathe Min:%f",min);
}

void eaverage() /*求各學生英語平均分、最高和最低分成績的函數*/
{ stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->english;
aver=sum/i;

p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{if(max<p1->english)
max=p1->english;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->english)
min=p1->english;
}
printf("English Average:%f",aver);
printf("English Max:%f",max);
printf("English Min:%f",min);
}

void comaverage() /*求各學生計算機平均分、最高和最低分成績的函數*/
{ stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->computer;
aver=sum/i;

p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{if(max<p1->computer)
max=p1->computer;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->computer)
min=p1->computer;
}
printf("Computer Average:%f",aver);
printf("Computer Max:%f",max);
printf("Computer Min:%f",min);
}

update(stu *p2) /*通過姓名查找來更新數據*/
{
char name[10]; /*p2為指向結構體struct student的指針*/
int b=0;
printf("Enter The Name"); /*輸入姓名*/
scanf("%s",name);

while(p2!=NULL)
{if(strcmp(name,p2->name)==0)
{
printf("Find you data\n");
scanf("Name:%s",p2->name);
scanf("Num:%s",p2->num);
scanf("Sex:%s",p2->sex);
scanf("Chinese:%d",p2->chinese);
scanf("Math:%d",p2->mathematic);
scanf("english:%d",p2->english);
scanf("Computer:%d",p2->computer);
printf("Success!");

b=1;}
else if(b==0)
printf("Sorry not Find data!");
p2=p2->next;}
if(b==0)
{print();
printf("Sorry not Find data!");
}
else
{
print();
printf("Finish!");
}
}

save(stu *p2) /*保留數據函數*/
{
FILE *fp;
char file[10];
printf("Enter file name"); /*輸入文件名*/
scanf("%s",file);
fp=fopen(file,"w");
while(p2!=NULL)
{
fprintf(fp,"%s",p2->name);
fprintf(fp,"%s",p2->num);
fprintf(fp,"%s",p2->sex);
fprintf(fp,"%d",p2->chinese);
fprintf(fp,"%d",p2->mathematic);
fprintf(fp,"%d",p2->english);
fprintf(fp,"%d",p2->computer);
p2=p2->next;
}
fclose(fp);
}

char password[7]="123456"; /*定義初始密碼*/

void main() /*主函數*/
{ int choice;
stu *p2;
char s[8];
int flag=0,i; /*標志項*/
int n=3;
do{ printf("Enter password:\n");
scanf("%s",s);
if(!strcmp(s,password)) /*進行密碼匹配驗證*/
{ printf("PASS\n\n\n");
flag=1;
break;
}
else{
printf("Error Enter again:\n");
n--;
}
}
while(n>0);
if(!flag)
{printf("you have Enter 3 times!"); /*輸入密碼超過了3次!!*/
exit(0); /*自動退出*/
}
/*密碼驗證成功後進入的界面*/

printf("~~~~~~~~~~\t\t\t~~~~~~~~~~~~\n"); /*操作界面*/
printf("\t\tWelcom to the Mis\n");
printf("Author:-----\tClass:------\tNum:------\n"); /*作者,班級和號碼*/
printf("Adress:HG\n"); /*地址*/
printf("%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
printf("\t\tEnter OP:\n");
printf("\n\n\n\n");
printf("==============\t\t==============\n");
printf("==============\t\t==============\n");
printf("\t\tEnter the MIS yes or no\n"); /*問進入系統與否*/

scanf("%d",&choice);
if(choice=='n'||choice=='N')
exit(1);

print();
while(1)
{
printf("Enter choice:");
scanf("%d",&i);
if(i<1||i>13)
{
printf("Enter num from 1 to 13:\n"); /*再從1-13中進行選擇*/
exit(1);
}

switch(i)
{ case 1:
p2=cindata(); /*其他數據是否繼續輸入的函數*/
break;
case 2:
p2=lookdata(head); /*查看數據的函數*/
break;
case 3:
insert(); /*通過比較學號來插入數據的函數*/
break;
case 4:
find(head); /*通過姓名查找查看數據的函數*/
break;
case 5:
update(head); /*通過姓名查找來更新數據*/
break;
case 6:
save(head); /*保留數據函數*/
break;
case 7:
print(); /*顯示或列印函數*/
break;
case 8:
caverage(); /*求各學生語文平均分、最高和最低分成績的函數*/
break;
case 9:
maverage(); /*求各學生數學平均分、最高和最低分成績的函數*/
break;
case 10:
eaverage(); /*求各學生英語平均分、最高和最低分成績的函數*/
break;
case 11:
comaverage(); /*求各學生計算機平均分、最高和最低分成績的函數*/
break;
case 12:
; /*空操作*/
case 13:
exit(1); /*退出*/
break;
}
scanf("%d",&i);
}
}

『叄』 用c語言編寫的代碼程序

c語言的源程序語法結構如下:
#include<stdio.h>//預處理語句
/* 自定義函數1*/
/* 自定義函數2*/
int main()
{
//main()主函數執行調用以上定義的函數的順序
return 0;//執行完畢 退出

}
示例如下:
#include <stdio.h>
int main()
{
printf("welcome to c language!!!\n");
return 0;

}

『肆』 C語言學生成績管理系統代碼

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

//外部函數聲明
void menu();
void line();

/* 定義全局變數其中n代表學生人數,ave[5]代表每科成績的平均分,high[5]每科成績的最高分,
min[5]代表每科成績的最低分,student_ave[100]代表每個學生五門成績的平均分*/
int n,i,j;
float ave[5]={0},high[5]={0},min[5]={0},student_ave[100];

//定義全局結構體
struct student
{
long int num; //學生學號
char name[20]; //學生姓名
float score[5]; //學生成績
}stu[100];

//主函數開始
int main()
{
void enter(); //enter:輸入學生成績函數(這是函數聲明)
void export(); //export:輸出學生成績函數(這是函數聲明)
void stat(); //stat:學生成績統計函數(這是函數聲明)
void rank(); //rank:學生成績排名函數(這是函數聲明)
void query(); //query:學生成績查詢函數(這是函數聲明)

//定義內部變數

//界面框架
menu();
printf(" 學生成績管理信息系統\n");
printf(">>請根據以下提示命令字元進行操作!\n");
printf("q:退出 a:成績輸入 p:成績輸出 s:成績統計 w:成績排名 t:成績查詢\n");
menu();

//函數調用,選擇成績管理方式
printf("請選擇成績管理方式>>");
while(1)
{
char c;
printf(">>\n");
scanf("%c",&c);
if (c=='q') printf("這是退出學生成績管理信息系統函數\n>>\n");break;
switch(c)
{
case'a':enter();break;
case'p':export(); break;
case's':stat();break;
case'v':rank();break;
case't':query();break;
default:("命令無效,請重新輸入!\n");
}
}
return 0;
}
//主函數部分結束

//定義函數
void menu()
{
printf("*******************************************************************************\n");
}

//定義下劃線函數
void line()
{
printf("--------------------------------------------------------------------------------\n");
}

//定義學生成績輸入函數開始
void enter()
{
menu();
printf("學生成績輸入\n請按以下格式進行數據輸入\n");
printf("請輸入學生學號姓名>>");
printf(" 學號 學生姓名\n");
printf("請輸入學生成績 >> ");
printf(" A成績 B成績 C成績 D成績 E成績\n");
printf("例如\n請輸入學生學號姓名>>");
printf("2012060402,張三\n");
printf("請輸入學生成績 >> ");
printf("95.5,97.0,89.0,92.0,85.0\n");
menu();
//輸入學生成績格式備注

printf("\n請輸入學生人數 >> ");
scanf("%d",&n);

//用for循環輸入學生成績
for(i=0;i<n;i++)
{
printf("請輸入學生學號姓名>>");
scanf("%ld,%s",&stu[i].num,stu[i].name);
printf("請輸入學生成績 >> ");
scanf("%f",&stu[i].score[0]);
scanf("%f",&stu[i].score[1]);
scanf("%f",&stu[i].score[2]);
scanf("%f",&stu[i].score[3]);
scanf("%f\n",&stu[i].score[4]);
getchar();
student_ave[i]=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2]+stu[i].score[3]+stu[i].score[4])/5;

//用for循環計算每科成績z總分
for(j=0;j<5;j++)
{
ave[j]=ave[j]+stu[i].score[j];
}

//用for循環得出每科成績最高分
for(j=0;j<5;j++)
{
if(high[j]<=stu[i].score[j])
{
high[j]=stu[i].score[j];
}
}

//用for循環得出每科成績最低分
for(j=0;j<5;j++)
{
if(i==0)
{
min[j]=stu[i].score[j];
}
if(min[j]>=stu[i].score[j])
{
min[j]=stu[i].score[j];
}
}

}
//學生成績輸入完成

//用for循環計算每科成績平均分
for(j=0;j<5;j++)
{
ave[j]=ave[j]/n;
}
getchar();
menu();
printf("\n");
}
//定義學生成績輸入函數結束

//定義學生成績輸出函數開始
void export()
{
int i;
printf(" 學號 姓名 成績A 成績B 成績C 成績D 成績E\n");
for(i=0;i<n;i++)
{
printf("%9ld %15s %7.1f %7.1f %7.1f %7.1f %7.1f\n",stu[i].num,stu[i].name,
stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4]);

}
menu();
}
//定義學生成績輸出函數結束

//定義學生成績統計函數開始
void stat()
{
printf("各科平均成績如下!\n");
line();
printf("\n");
printf(" 成績A 成績B 成績C 成績D 成績E\n");

//這是每科成績平均分
for(i=0;i<5;i++)
{
printf(" %6.1f ",ave[i]);
}
printf("\n");
printf("\n");

//只是每科成績的最高分
printf("各科最高分如下!\n");
line();
printf("\n");
printf(" 成績A 成績B 成績C 成績D 成績E\n");
for(j=0;j<5;j++)
{
printf(" %6.1f ",high[j]);
}
printf("\n");
printf("\n");

//這是每科成績最低分
printf("各科最低分如下!\n");
line();
printf("\n");
printf(" 成績A 成績B 成績C 成績D 成績E\n");
for(i=0;i<5;i++)
{

printf(" %6.1f ",min[i]);
}
printf("\n");
printf("\n");
}
//定義學生成績統計函數結束

//定義學生成績排名函數開始
void rank()
{
int k=1,z;
float t=0;
float student_high[100]={0};
printf("學生成績排名如下:\n\n");
line();
printf("\n");
printf("名次 學號 姓名 成績A 成績B 成績C 成績D 成績E 平均分 \n");

//把每個學生五門課的成績按從大到小的順序排列並存在數組student_high[]中去
for(i=0;i<n;i++)
{
student_high[i]=student_ave[i];
}
for(j=0;j<n;j++)
{
for(i=0;i<n-j;i++)
{
if(student_high[i]<=student_high[i+1])
{
t=student_high[i+1];
student_high[i+1]=student_high[i];
student_high[i]=t;
}
}
}

//按成績排名輸出學生成績信息
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(student_high[i]==student_high[i+1])
{
i++;
}
if(student_high[i]==student_ave[j])
{
printf("%d %ld %15s %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f\n",k,stu[j].num,stu[j].name,
stu[j].score[0],stu[j].score[1],stu[j].score[2],stu[j].score[3],stu[j].score[4],student_ave[j]);
for(z=j+1;z<n;z++)
{
if(student_high[i]==student_ave[z])
{
k++;
}
}

}
}
k++;
}

line();
printf("\n");
}
//定義學生成績排名函數結束

//定義學生成績查詢函數開始
void query()
{
//查詢成績格式
char c2,shu_name[20]; //c2代表查詢成績控制字元。shu_name[]代表輸入查詢姓名,shu_num代表輸入查詢學號
int shu_num;
menu();
printf("學生成績查詢\n請按以下方式查詢\na:按學生姓名查詢 b:按學生學號查詢 q:退出\n");
menu();
printf("\n\n");

//選擇查詢方式
while(c2!='q')
{
printf("請選擇查詢成績方式>>");
scanf("%c",&c2);
getchar();

//按姓名查詢成績
if(c2=='a')
{
line();
printf("請輸入學生姓名>>");
scanf("%s",shu_name);
getchar();
for(i=0;i<n;i++)
{
if(strcmp(shu_name,stu[i].name)==0)
{
printf(" 學號 姓名 成績A 成績B 成績C 成績D 成績E\n");
printf("%ld %15s %7.1f %7.1f %7.1f %7.1f %7.1f\n",stu[i].num,stu[i].name,
stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4]);
}
else if(shu_name!=stu[i].name&&i==(n-1))
{
printf("無此學生成績\n");
}

}
line();
printf("\n");
}

//按學號查詢成績
else if(c2=='b')
{
line();
printf("請輸入學生學號>>");
scanf("%d",&shu_num);
getchar();
for(i=0;i<n;i++)
{
if(shu_num==stu[i].num)
{
printf(" 學號 姓名 成績A 成績B 成績C 成績D 成績E\n");
printf("%ld %15s %7.1f %7.1f %7.1f %7.1f %7.1f\n",stu[i].num,stu[i].name,
stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4]);
}
else if(shu_num!=stu[i].num&&i==(n-1))
{
printf("無此學生成績\n");
}
}
line();
printf("\n");
}

}
line();
printf("\n\n");
}
//定義學生成績查詢函數結束

『伍』 求簡單C語言程序代碼!

輸入2個正整數m和n,求其最大公約數和最小公倍數

#include

#include

int main()

int m,n,p,q,s,r;

printf("請輸入兩個正整數;m,n ");

scanf("%d,%d",&m,&n);

#include<stdio.h>

main()

int a,b,t=0;

scanf("%d %d",&a,&b);

if (a<b)

printf("%d %d %d %d %d",(a+b),(a-b),(a/b),(a*b),(a%b));

}

主要特點

C語言是一種結構化語言,它有著清晰的層次,可按照模塊的方式對程序進行編寫,十分有利於程序的調試,且c語言的處理和表現能力都非常的強大,依靠非常全面的運算符和多樣的數據類型,可以輕易完成各種數據結構的構建,通過指針類型更可對內存直接定址以及對硬體進行直接操作,因此既能夠用於開發系統程序,也可用於開發應用軟體。

以上內容參考:網路-c語言

『陸』 c語言代碼有哪些

如下:

1、乘法表。用C語言輸出9*9乘法口訣。共9行9列,i控制行,j控制列。

2、編寫函數countpi,利用公式計算π的近似值,當某一項的值小於10-5時,認為達到精度要求,請完善函數。將結果顯示在屏幕上並輸出到文件p7_3.out中。

3、反向輸出。完善程序,實現將輸入的字元串反序輸出,如輸入windows 輸出swodniw。

4、替換輸出:編寫函數replace(char *s,char c1,char c2)實現將s所指向的字元串中所有字元c1用c2替換,字元串、字元c1和c2均在主函數中輸入,將原始字元串和替換後的字元串顯示在屏幕上,並輸出到文件p10_2.out中。

5、解決排序問題:寫一個void sort(int *x,int n)實現將x數組中的n個數據從大到小排序。n及數組元素在主函數中輸入。將結果顯示在屏幕上並輸出到文件p9_1.out中。

C語言語言特點

簡潔的語言:C語言包含的各種控制語句僅有9種,關鍵字也只有32個,程序的編寫要求不嚴格且以小寫字母為主,對許多不必要的部分進行了精簡。

具有結構化的控制語句:C語言是一種結構化的語言,提供的控制語句具有結構化特徵,如for語句、if...else語句和switch語句等。可以用於實現函數的邏輯控制,方便麵向過程的程序設計。

『柒』 c語言學生信息管理系統代碼

代碼如下:

#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
typedef struct examinee //考生信息結構
{ char examno[20]; //准考證號
char name[10]; //姓名
char sex[4]; //性別
short age; //年齡
char examtype[10]; //報考科目
}ElemType;

typedef struct Node //定義鏈表結點
{
ElemType data; //數據域
struct Node *next; //指針域
}Node,*List,*position;

List make_empty( List L ); //創建一個帶頭結點的空表
int is_empty( List L ); //測試鏈表是否是空表
int is_last( position p, List L ); //測試當前位置是否是表尾
position make_node( position p,int n ); //創建結點並輸入考生信息
void put_information( position p ); //是否輸出該考生信息
void put_name_information( List L ); //輸出姓名為xx的考生信息
int put_pos_information( position p ); //輸出該地址考生信息
void link_to_tail( List L, position p ); //將結點連接到表尾
int ciculation_make(); //循環創建考生信息
int judge_put_all(); //是否輸出所有考生信息
void put_all(List L); //輸出所有考生信息。
position find( List L ); //查找第一個姓名為xx的元素並返回位置
position find_previous( List L ); //查找第一個姓名為xx的元素並返回該元素直接前驅的位置
//int judge_delete_val(); //詢問是否刪除考生數據
int delete_val( List L ); //刪除指定考生信息並輸出其信息
void menu(List L); //菜單函數
List L;
//position p;

int
main( void )
{
List L = NULL; //定義頭結點指針
position p = NULL; //定義表工作指針
L = make_empty( L ); //創建空表
printf(" ★★考生報名管理程序★★ ---------------------------------------- ");
menu(L);
return 0;
}

//創建一個帶頭結點的空表
List
make_empty( List L)
{
L = ( List ) malloc (sizeof( Node ));
if(NULL == L)
{
printf("內存分配失敗");
exit( 1 );
}
L->next = NULL;
//printf("空表創建成功。 ");
return L;
}

//創建結點並輸入考生信息
position
make_node( position p ,int n)
{
if(n) //n為1是創建結點並輸入,n為0是修改
{
p = ( position ) malloc ( sizeof ( Node ));
p->next = NULL ;
}
printf("請輸入考生准考證號:");
gets(p->data.examno);
printf("請輸入考生姓名:");
gets(p->data.name);
do
{
printf("請輸入考生性別,只能輸入「男」或者「女」:");
gets(p->data.sex);
}
while( 0 != strcmp( p->data.sex, "男" ) && 0 != strcmp( p->data.sex, "女" )); //判斷性別是否有誤
printf("請輸入考生年齡:");
scanf("%hd",&p->data.age);
getchar(); //如果把這句刪掉,就「無法執行」下面的報考類別
/*下面的do while用來判斷報考類別是否輸入有誤*/
do
{
printf("請輸入報考類別,只能輸入「數學」或「英語」或者「數據結構」:");
gets(p->data.examtype);
}
while( 0 != strcmp( "英語", p->data.examtype ) && 0 != strcmp( "數學", p->data.examtype ) && 0 != strcmp( "數據結構", p->data.examtype ));
if(n)
{
printf("報名成功 ");
}
else
{
printf("修改成功 ");
}
return p;
}

//前插法;
void
link_to_tail( List L, position p)
{
p->next = L->next;
L->next = p;
}

//查找第一個姓名為xx的元素並返回位置
position
find( List L )
{
position p = L->next;
char name[10];
printf("請輸入你要查找的考生姓名:");
gets(name);
while( p != NULL && 0 != strcmp( p->data.name , name))
{
p=p->next;
}
return p;
}

//測試鏈表是否是空表
int
is_empty( List L )
{
return L->next == NULL;
}

//測試當前位置是否是表尾
int
is_last( position p, List L )
{
return p->next == NULL;
}

//輸出姓名為xx的考生信息
void
put_name_information( List L )
{
position p = find(L);
if(p!=NULL)
{
printf("您要查找的考生信息: ");
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s ",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);
}
else
{
printf("沒有您要找的學生。 ");
}

}

//循環創建考生信息
int
ciculation_make()
{
int n = 2;
do
{
printf("是否繼續創建考生信息?是請輸入「1」,不是請輸入「0」:");
scanf("%d",&n);
getchar();
}
while( n != 0 && n != 1);
return n;
}

//是否輸出考生信息
void
put_information( position p )
{
int n=2;
do
{
printf("是否輸出該考生信息?是請輸入「1」,不是請輸入「0」:");
scanf("%d",&n);
getchar();
}
while( n != 0 && n != 1);
if(n)
{
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s ",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);
}
}


//是否輸出所有考生信息
int
judge_put_all()
{
int n = 2;
do
{
printf("是否輸出所有考生信息?是請輸入「1」,不是請輸入「0」:");
scanf("%d",&n);
getchar();
}
while( n != 0 && n != 1);
return n;
}

//輸出所有考生信息
void
put_all(List L)
{
if(L->next == NULL)
{
printf("現無考生報名! ");
}
else
{
position p=L->next;
while( p != NULL )
{
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s ",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);
p=p->next;
}
}
//getchar();

}

//詢問是否刪除考生數據
int
judge_delete_val()
{
int n = 2;

do
{
printf("是否要刪除某個考生數據?是請輸入「1」,不是輸入「0」:");
scanf("%d",&n);
getchar();
}
while( n != 0 && n != 1);
return n;
}

//查找第一個姓名為xx的元素並返回其直接前驅的位置
position
find_previous( List L )
{
position q = L;
position p = L->next;
char name[10];
printf("請輸入你要查找的考生姓名:");
gets(name);
while( p != NULL && 0 != strcmp( p->data.name , name))
{
q=p;
p=p->next;
}
if( p != NULL )
{
return q;
}
else
return p;
}

//刪除指定考生信息並輸出其信息
int
delete_val(List L)
{
int n=2;
position q=NULL;
position p=find_previous( L ); //返回考生信息地址
if( NULL == p )
{
printf("你要刪除的考生不存在 ");
return 0;
}
else
{
q = p->next;
p->next = q->next;
printf("刪除成功。 刪除的考生信息為: ");
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s ",q->data.examno,q->data.name,q->data.sex,q->data.age,q->data.examtype);
free(q);
return 1;
}

}

//輸出該地址考試信息
int
put_pos_information( position p )
{
if(p != NULL )
{
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s ",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);
return 1;
}
else
{
printf("沒有您要查找的學生。");
return 0;
}
}
//菜單函數
void
menu(List L)
{
printf(" a. 考生報名入口 ");
printf(" b. 查詢考生信息 ");
printf(" c. 修改考生信息 ");
printf(" d. 刪除考生信息 ");
printf(" e. 全部考生信息 ");
printf(" f. 程序作者信息 ");
printf(" g. 退出程序 ");
char n='h';

while(n != 'g')
{
do //確定正確輸入
{
printf("請通過字母序號選擇功能:");
n = getchar();
getchar();
putchar(' ');
if( n < 'a' || n > 'g')
{
printf("錯誤的字母序號。 ");
}
}
while( n < 'a' || n > 'g' );
switch (n)
{
case 'a':
{
printf("請輸入報名考生信息: ");
position p = make_node( p, 1 ); //創建新結點
link_to_tail( L, p ); //將新結點連接到表上
put_information( p ); //是否輸出該考生信息
putchar(' ');
}
break;

case 'b':
{
put_name_information( L );
putchar(' ');
}
break;

case 'c':
{
int n=0;
position p = NULL;
printf("您正在進行修改操作。 ");
p = find(L);
n = put_pos_information( p );
if(n)
{
make_node( p , 0 );
put_information( p ); //是否輸出該考生信息
}
putchar(' ');
}
break;

case 'd':
{
printf("您正在進行刪除操作。 ");
delete_val( L );
putchar(' ');
}
break;

case 'e':
{
put_all( L );
putchar(' ');
}
break;

case 'f':
{
printf(" 修改日期 版本號 修改人 修改內容 ");
printf(" -------------------------------------------------------- ");
printf(" 2018.6.19 v2.0 陳百川 增加主菜單 ");
printf(" 2018.6.23 v3.0 陳百川 增加生成文件功能 ");
printf(" 該版本號為v2.0 ");
putchar(' ');
}
break;

default:
break;
}
}
printf(" 感謝本次使用,祝您生活愉快。");
getch();
}

(7)c語言系統代碼擴展閱讀:

C語言是一門通用計算機編程語言,廣泛應用於底層開發。C語言的設計目標是提供一種能以簡易的方式編譯、處理低級存儲器、產生少量的機器碼以及不需要任何運行環境支持便能運行的編程語言。

盡管C語言提供了許多低級處理的功能,但仍然保持著良好跨平台的特性,以一個標准規格寫出的C語言程序可在許多電腦平台上進行編譯,甚至包含一些嵌入式處理器(單片機或稱MCU)以及超級電腦等作業平台。

二十世紀八十年代,為了避免各開發廠商用的C語言語法產生差異,由美國國家標准局為C語言制定了一套完整的美國國家標准語法,稱為ANSI C,作為C語言最初的標准。[1]目前2011年12月8日,國際標准化組織(ISO)和國際電工委員會(IEC)發布的C11標準是C語言的第三個官方標准,也是C語言的最新標准,該標准更好的支持了漢字函數名和漢字標識符,一定程度上實現了漢字編程。

C語言是一門面向過程的計算機編程語言,與C++,Java等面向對象的編程語言有所不同。

其編譯器主要有Clang、GCC、WIN-TC、SUBLIME、MSVC、Turbo C等。

參考資料:

網路——C語言

熱點內容
徵婚交友源碼 發布:2025-02-05 17:45:24 瀏覽:917
3nvm伺服器怎麼搭建 發布:2025-02-05 17:43:52 瀏覽:660
cocosandroid開發 發布:2025-02-05 17:22:17 瀏覽:668
編程員發型 發布:2025-02-05 17:09:18 瀏覽:226
網站會員管理源碼 發布:2025-02-05 17:03:32 瀏覽:193
伺服器埠怎麼調節 發布:2025-02-05 16:57:41 瀏覽:47
樂山海棠社區民意上傳 發布:2025-02-05 16:55:52 瀏覽:510
編程老爺爺 發布:2025-02-05 16:48:20 瀏覽:130
支持ftp的免費空間 發布:2025-02-05 16:32:00 瀏覽:891
python時間比較 發布:2025-02-05 16:31:46 瀏覽:52