#include?cstdio

十年建站經(jīng)驗(yàn), 網(wǎng)站設(shè)計(jì)、成都網(wǎng)站設(shè)計(jì)客戶的見證與正確選擇。成都創(chuàng)新互聯(lián)公司提供完善的營銷型網(wǎng)頁建站明細(xì)報(bào)價(jià)表。后期開發(fā)更加便捷高效,我們致力于追求更美、更快、更規(guī)范。
void?menu(){
printf("1.求兩個(gè)數(shù)的和\n");
printf("2.求兩個(gè)數(shù)的差\n");
printf("3.求兩個(gè)數(shù)的積\n");
printf("4.求兩個(gè)數(shù)的商\n");
printf("5.求兩個(gè)數(shù)的余\n");
}
int?add(int?x,int?y){return?x+y;}
int?sub(int?x,int?y){return?x-y;}
int?mul(int?x,int?y){return?x*y;}
int?drv(int?x,int?y){return?x/y;}
int?mod(int?x,int?y){return?x%y;}
int?main(){
int?a,b,n;
printf("Please?input?2?numbers:");
scanf("%d%d",a,b);
menu();
printf("Please?input?the?number:");
scanf("%d",n);
switch(n){
case?1:printf("%d\n",add(a,b));break;
case?2:printf("%d\n",sub(a,b));break;
case?3:printf("%d\n",mul(a,b));break;
case?4:printf("%d\n",drv(a,b));break;
case?5:printf("%d\n",mod(a,b));break;
default:printf("Wrong?number!");
}
}
望采納
代碼:
# include stdio.h
# includestdlib.h
char stu_no[10][10];
int c_math[10],c_en[10],c_computer[10],point[10],average[10];
int i,j,max;
char c;
void input()
{
for(i=0;i=9;i++) /*輸入學(xué)生成績*/
{
printf("請(qǐng)輸入學(xué)號(hào):");
scanf("%s",stu_no[i]);
printf("\n請(qǐng)輸入數(shù)學(xué)成績:");
scanf("%d",c_math[i]);
printf("\n請(qǐng)輸入英語成績:");
scanf("%d",c_en[i]);
printf("\n請(qǐng)輸入計(jì)算機(jī)基礎(chǔ)成績:");
scanf("%d",c_computer[i]);
}
for(i=0;i=10;i++) /*計(jì)算總分跟平均分*/
{
point[i]=c_math[i]+c_en[i]+c_computer[i];
average[i]=point[i]/3;
}
}
void paixu()
{
printf("成績按從高到低排列為:\n");
printf("\n學(xué)號(hào) 數(shù)學(xué) 英語 計(jì)算機(jī)基礎(chǔ) 總分 平均分\n");
for (i=0;i=10;i++)
{ for(j=1;j=10;j++)
if (point[i]point[j])
max=i;
printf("%s,d,%d,%d,%d,%d,%d\n",stu_no[max],c_math[max],c_en[max],c_computer[max],point[max],average[max]);
}
}
void main()
{
input();
paixu();
}
#include math.h
int primeNum(int p)
{
int i, q;
/* Negative number is not a prime */
if (p 0)
return 0;
q = (int) sqrt(p);
for (i = 2; i q; i++)
if ((p % i) == 0)
return 0;
/* No factor of p is found */
return 1;
}
/*原理::
從2-sqrt(x)的數(shù)中看是否有可以整除的, 如果沒有, 則為素?cái)?shù).
*/
五、 課程設(shè)計(jì)小結(jié)心得體會(huì)
1設(shè)計(jì)思想
1)、設(shè)定一個(gè)一維數(shù)組,可先按員工序號(hào)設(shè)定每位員工的工資
2)、利用While語句和Prinft語句完成用戶菜單的設(shè)計(jì)
功能為:第1項(xiàng) 設(shè)為員工編號(hào)和工資數(shù)據(jù)
第2項(xiàng) 設(shè)為修改員工工資數(shù)據(jù)
第3項(xiàng) 設(shè)為查詢員工工資數(shù)據(jù)
第4項(xiàng) 設(shè)為結(jié)束系統(tǒng)
3)、當(dāng)用戶選擇1、2項(xiàng)時(shí),需輸入員工編號(hào),所以需要設(shè)計(jì)編號(hào)校正功能,如果出錯(cuò)可輸出“The error employe number”
4)、當(dāng)選擇2時(shí),進(jìn)行工資數(shù)據(jù)的修改,并將新數(shù)據(jù)存回該員工的工資數(shù)組中
5)、利用for循環(huán)中判斷語句,將用戶工資數(shù)與數(shù)組中的工資數(shù)進(jìn)行比較,如相同則輸出,將計(jì)數(shù)器加1,如此下去,直到把整個(gè)數(shù)組遍歷一遍
6)、判斷計(jì)數(shù)器是否為0, 是0表示找不到相符的工資,如果不為0,則輸出共查出幾比相符的工資
以上當(dāng)然里面也涉及了“函數(shù)的模塊化”理念,可以避免但需要重復(fù)打印頭文件時(shí)重復(fù)編寫打印信頭的語句。像這樣的程序是多見的,這樣不但降低了程序還發(fā)效率,而且耗時(shí)浪費(fèi)資源“共用體”的使用簡化了程序的“復(fù)雜”性,正如(4)中,學(xué)號(hào)與姓名同時(shí)表示一個(gè)人,但在函數(shù)使用了“共用體”,從而程序的簡單可以便于糾錯(cuò),查找問題,避免了代碼的重復(fù),這樣就給編譯時(shí)帶來了一定的難度與“量”的繁雜。一般不采取這樣的做法,力求“簡單、明了、清晰”。
只是個(gè)例子,不可照抄。
實(shí)驗(yàn)內(nèi)容與要求:
[實(shí)驗(yàn)內(nèi)容]
1、 通過本試驗(yàn)初步培養(yǎng)計(jì)算機(jī)邏輯解題能力。熟練掌握賦值語句和if語句的應(yīng)用;掌握switch多路分支語句和if嵌套語句的使用
2、 將前期所學(xué)習(xí)到的基本數(shù)據(jù)類型、運(yùn)算符和表達(dá)式等程序設(shè)計(jì)基礎(chǔ)知識(shí)運(yùn)用于具體的程序設(shè)計(jì)。
3、 進(jìn)一步熟練掌握輸入輸出函數(shù)scanf, printf和getchar的使用,熟悉math.h中常用數(shù)學(xué)函數(shù)的使用方法
4、 掌握循環(huán)語句的應(yīng)用方法。
5、 了解隨機(jī)數(shù)生成函數(shù)。
[實(shí)驗(yàn)要求]
在規(guī)定期限獨(dú)立完成實(shí)驗(yàn)內(nèi)容
1、 提交實(shí)驗(yàn)報(bào)告(電子版)
2、 提交相應(yīng)源程序文件(文件名 EX6_x姓名.c, 如EX6_1彭健.c)
3、 要求從簡單到復(fù)雜,后面的要求均在前面的基礎(chǔ)上進(jìn)行修改,前六題,每題均需要保留各自的程序,六題以后,每題均在前一題基礎(chǔ)上修改,保留最后一個(gè)程序即可(如做到第九題,則保留EX6_9姓名.c,做到第11題,則保留ex6_11姓名.c)
二、實(shí)驗(yàn)原理和設(shè)計(jì)方案:
1、函數(shù)頭的選則,while循環(huán)語句,switch(case)語句,條件表達(dá)式,if else條件語句,自增運(yùn)算符,設(shè)置復(fù)雜變量,輸出隨機(jī)操作數(shù)。
2、 變量要有分?jǐn)?shù)變量和等級(jí)變量,要有選擇算法題數(shù)的變量和計(jì)算正確與否的變量,要有隨機(jī)輸出的兩個(gè)操作數(shù)變量和自己按運(yùn)算符號(hào)輸入結(jié)果的變量,最后還有判斷是否要進(jìn)行的變量字符。中間結(jié)果有選擇運(yùn)算符的switch()和分?jǐn)?shù)等級(jí)的switch()和錯(cuò)題對(duì)題的自增和選擇運(yùn)算符計(jì)算的自增。
3、 問題的分析方法:先考慮設(shè)置整形變量和字符變量,考慮到要不斷循環(huán)計(jì)算,選擇用while語句來循環(huán)。在循環(huán)體中,將前面的輸出提示運(yùn)算符,和自行選擇運(yùn)算符、答案及輸出隨機(jī)操作數(shù)完成。再用switch語句對(duì)選擇的運(yùn)算符進(jìn)行判斷,并用變量進(jìn)行自增運(yùn)算,計(jì)算出錯(cuò)題于對(duì)題個(gè)數(shù)和選擇了那種運(yùn)算符號(hào)。在循環(huán)體最后用if else語句來判斷是否繼續(xù)執(zhí)行還是跳出循環(huán)。最后根據(jù)自增計(jì)算的結(jié)果和公式進(jìn)行分?jǐn)?shù)計(jì)算,并用switch語句來是想等級(jí)的制定。
三、源代碼
#includestdio.h
#includestdlib.h
#includetime.h
void main()
{
..........
}
四、試驗(yàn)結(jié)果和啟發(fā)
因?yàn)檩斎難要繼續(xù)循環(huán),所以選擇用while語句。在while語句中要結(jié)合前面的按提示計(jì)算,并嵌套switch語句并用條件表達(dá)式,來計(jì)算結(jié)果正確與否,計(jì)算的題型是什么。最后再用switch語句來完成分?jǐn)?shù)等級(jí)的判斷。
五、實(shí)驗(yàn)體會(huì):
描述自己在編程或程序編譯運(yùn)行中遇到的難點(diǎn)和問題及解決的辦法。
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
void cut();
void in();
void display();
int keep();
int enter();
struct msg
{
int num;
char name[20];
float score1;
float score2;
float score3;
double ave;
}
main()
{
struct msg student[10];
int i,n=0,k,m;
printf("請(qǐng)輸入學(xué)員信息.\n");
n=enter(student);
printf("\n排序前學(xué)員信息如下:\n");
printf("\t學(xué)號(hào) \t姓名 \t平均成績\n");
for(i=0;in;i++)
printf("\t%d \t%s \t%f\n",student[i].num,student[i].name,student[i].ave);
printf("\n");
printf("\n排序后學(xué)員信息如下:\n");
display(student,n);
printf("\n\n是否要插入新學(xué)員?y or n");
k=keep();
if(k==0) exit(k); //如果輸入的不是y退出程序
else
{
in(student,n);
}
printf("\n\n是否要?jiǎng)h除某個(gè)學(xué)員?y or n");
k=keep();
if(k==0) exit(k);
else
{
m=n+1; //之前插入了一個(gè)學(xué)生,所以數(shù)組增加1
cut(student,m);
}
}
int keep() //是否繼續(xù)條件判斷函數(shù)
{
char ans;
fflush(stdin);
ans=getchar();
if (ans=='y')
return 1;
else
return 0;
}
int enter(struct msg student[10]) //錄入結(jié)構(gòu)數(shù)據(jù)函數(shù)
{
int i,k,n=0;
for(i=0;;i++)
{
student[i].num=i+1;
printf("\n學(xué)號(hào):%d\n",student[i].num);
printf("姓名: ");
fflush(stdin);
gets(student[i].name);
if(i==0) printf("\n三門成績:\n");
printf("成績1:");
scanf("%f",student[i].score1);
printf("成績2:");
scanf("%f",student[i].score2);
printf("成績3:");
scanf("%f",student[i].score3);
student[i].ave=(student[i].score1+student[i].score2+student[i].score3)/3.0;
n++;
printf("是否要繼續(xù)?y or n");
k=keep();
if(k==1)
continue;
else
{
break;
}
}
return n;
}
void display(struct msg student[],int n) //排序函數(shù),多次調(diào)用
{
int i,j,temp1;
char temp2[20];
double temp;
printf("\t學(xué)號(hào) \t姓名 \t平均成績\n");
for(i=0;in;i++)
{
for(j=0;jn-i-1;j++)
{
if(student[j].avestudent[j+1].ave)
{
temp=student[j].ave;
student[j].ave=student[j+1].ave;
student[j+1].ave=temp;
temp1=student[j].num;
student[j].num=student[j+1].num;
student[j+1].num=temp1;
strcpy(temp2,student[j].name);
strcpy(student[j].name,student[j+1].name);
strcpy(student[j+1].name,temp2);
}
}
}
for(i=0;in;i++)
printf("\t%d \t%s \t%f\n",student[i].num,student[i].name,student[i].ave);
}
void in(struct msg student[],int n) //插入函數(shù)
{
int k;
k=n+1;
printf("\n請(qǐng)輸入要插入學(xué)員的信息\n");
student[n].num=k;
printf("\n學(xué)號(hào):%d\n",student[n].num);
printf("姓名:");
fflush(stdin);
gets(student[n].name);
printf("\n三門成績:");
printf("\n成績1:");
scanf("%f",student[n].score1);
printf("成績2:");
scanf("%f",student[n].score2);
printf("成績3:");
scanf("%f",student[n].score3);
student[n].ave=(student[n].score1+student[n].score2+student[n].score3)/3.0;
printf("\n插入新學(xué)員后學(xué)員的信息如下\n");
display(student,k);
}
void cut(struct msg student[],int n)//刪除函數(shù)
{
int i,k1,j,m;
printf("輸入要?jiǎng)h除的學(xué)員的學(xué)號(hào):");
scanf("%d",k1);
for(i=0;in;i++)
{
if(student[i].num==k1)
break;
}
for(j=i;jn-1;j++)
{
student[j].num=student[j+1].num;
strcpy(student[j].name,student[j+1].name);
student[j].ave=student[j+1].ave;
}
m=n-1;
printf("\n刪除后學(xué)員的信息如下:\n");
display(student,m);
}
這個(gè)也是和你差不多的學(xué)生成績?cè)O(shè)計(jì),對(duì)其進(jìn)行排序,刪除,添加,研究一下你那個(gè)應(yīng)該就差不多了
網(wǎng)頁題目:c語言程序設(shè)計(jì)函數(shù)報(bào)告,c語言程序設(shè)計(jì)總結(jié)報(bào)告
網(wǎng)頁URL:http://chinadenli.net/article3/dsiciis.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、做網(wǎng)站、靜態(tài)網(wǎng)站、定制開發(fā)、網(wǎng)站導(dǎo)航、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)