本文目錄一覽:
- 1、用C語言編寫一個求定積分的程序
- 2、c語言編一個學生成績統計程序
- 3、c語言編寫選擇題計分程序
- 4、用C語言設計一個學生成績統計程序,
- 5、1、用C語言編寫一個程序計算自己的期末考試成績的總分。(要求各科成績從鍵盤
用C語言編寫一個求定積分的程序
這是辛普森積分法。
給你寫了fun_1( ),fun_2(),請自己添加另外幾個被積函數。
調用方法 t=fsimp(a,b,eps,fun_i);
a,b –上下限,eps — 迭代精度要求。
#includestdio.h
#includestdlib.h
#include math.h
double fun_1(double x)
{
return 1.0 + x ;
}
double fun_2(double x)
{
return 2.0 * x + 3.0 ;
}
double fsimp(double a,double b,double eps, double (*P)(double))
{
int n,k;
double h,t1,t2,s1,s2,ep,p,x;
n=1; h=b-a;
t1=h*(P(a)+P(b))/2.0;
s1=t1;
ep=eps+1.0;
while (ep=eps)
{
p=0.0;
for (k=0;k=n-1;k++)
{
x=a+(k+0.5)*h;
p=p+P(x);
}
t2=(t1+h*p)/2.0;
s2=(4.0*t2-t1)/3.0;
ep=fabs(s2-s1);
t1=t2; s1=s2; n=n+n; h=h/2.0;
}
return(s2);
}
void main()
{
double a,b,eps,t;
a=0.0; b=3.141592653589793238; eps=0.0000001;
// a definite integral by Simpson Method.
t=fsimp(a,b,eps,fun_1);
printf(“%g\n”,t);
t=fsimp(a,b,eps,fun_2);
printf(“%g\n”,t);
// …
printf(“\n Press any key to quit…”);
getch();
}
c語言編一個學生成績統計程序
#include
stdio.h
void
main()
{
int
i,
n,
reno;
float
score[30],
avr,
a,
b,
c;
char
name[30][9];
for(i
=
0;
i
30;
i++)
{
printf(“%d號的成績:”,
i+1);
scanf(“%f”,
score[i]);
if(score[i]
0)
break;
printf(“%d號的姓名:”,
i+1);
scanf(“%s”,
name[i]);
}
n
=
i;
printf(“統計不及格人數:\n”);
reno
=
0;
avr
=
0;
for(i
=
0;
i
n;
i++)
{
if(
score[i]
60)
{
reno++;
printf(“%d,
%s\n”,
i+1,
name[i]);
}
avr
+=
score[i];
}
printf(“不及格人數為%d\n\n”,
reno);
printf(“統計成績在平均分及平均分之上的學生人數:\n”);
avr
/=
n;reno
=
0;
for(i
=
0;
i
n;
i++)
{
if(score[i]
=
avr)
{
reno++;
printf(“%d,
%s\n”,
i+1,
name[i]);
}
}
printf(“成績在平均分及平均分之上的學生人數為%d\n\n”,
reno);
printf(“統計各分數段的人數及所佔百分比(分數段為60,60~79,=80):\n”);
a
=
b
=
c
=0;
for(i
=
0;
i
n;
i++)
{
if(score[i]
60)
a++;
else
if(score[i]
=
80)
c++;
else
b++;
}
printf(“60:\t%.1f%%\n60~79:\t%.1f%%\n=80:\t%.1f%%\n”,100*a/n,100*b/n,100*c/n);
}
c語言編寫選擇題計分程序
我假定你說的這些選擇題的位置是固定的,我的意思就是第二題後面是第四題,中間沒有別的題了。也就是說你輸入的必須準確,#includestdio,h#includectype.h#define S 5 //每題的得分,以後不一樣的話可以更改int main(){int anwser[40]={‘A’,’D’,’D’,’C’,’A’,’A’,’B’,’D’,’A’,’C’,’C’,’A’,’A’,’B’,’D’,’A’,’B’,’C’,’C’,’B’,’D’,’A’,’A’,’A’,’A’,’C’,’C’,’D’,’B’,’D’,’B’,’D’,’C’,’C’,’C’,’C’,’B’,’A’,’D’,’C’,’C’,’C’,’D’};//這些是正確答案 數組大小那塊我就不要求可移植性了 你懂得….int sum=0;//總分數計數器int m=0;char ch; while((ch=getchar())!=EOFch!=’\n’){ ch=toupper(ch);//轉成大寫 if(ch==answer[m]) sum+=S; m++;} printf(“%d\n”,sum);return 0;} 這位帥哥還是美女的……我相信你是懂c語言的….因為沒有在編譯器上實際操作…可能會有些紕漏..(剛完吃飯…)你要按照下列格式輸入答案比如(大小寫隨便):a b c d …..(這個程序能否正確運行你輸入準確是先決條件….)當然了 我這算是個提示程序….還可以有很方便的。。就是你在一整個文件中輸入所有同學的答案 然後在另一個文件中顯示對應分數。。。如果你是一個學c的學生的話 你該知道怎麼弄 要是不是的話 你可以再找我要……..
用C語言設計一個學生成績統計程序,
改好了,問題不大,我都寫在注釋里了:
#includestdio.h
#includemath.h
#define N 35
#define COURSE 4
struct student
{
char num[10];/*如果把num當作字元串的話,不能用int,而是char數組。不然就用int num;*/
float score[4];
float sum;
float aver;
}
stu[N];
void main()
{
void Input(struct student stu[]);
void count(struct student stu[]);
void sort(struct student stu[]);
void find(struct student stu[]);
sqrt(1.0);/*不知你用什麼編譯器,如果TC的話,有個BUG。就是結構體里有float型的話,要加這句,不然會報錯*/
Input(stu);
count(stu);
find(stu);
/*為什麼你的程序里沒有執行著幾個函數咧?*/
}
void Input(struct student stu[])
{
int i,j;
printf(“Enter No.and score as :score1 score2 score3 score4\n”);
for (i=0;iN;i++)
{
scanf(“%s”,stu[i].num);/*用%s輸入字元串*/
for (j=0;jCOURSE;j++)
{
scanf(“%f”,stu[i].score[j]);
}
}
}
void count(struct student stu[])
{
float sum,aver;
int i,j;
for(i=0;iN;i++)
{
sum=0;
for(j=0;j5;j++)
sum+=stu[i].score[j];
aver=sum/4;
stu[i].sum=sum;
stu[i].aver=aver;
}
}
void sort(struct student stu[])
{
int i,j,k;
struct student temp;
for(i=0;iN;i++)
{
k=i;
for(j=i+1;jN;j++)
if(stu[k].sumstu[j].sum)k=j;
if(k!=i)
{
temp=stu[i];
stu[i]=stu[k];
stu[k]=temp;
}
}
printf(“number score1 score2 score3 score4 sum average \n”);
for(i=0;iN;i++)
printf(“%-8s%-8.2f%-8.2f%-8.2f%-8.2f%-8.2f%-8.2f\n”,stu[i].num,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].sum,stu[i].aver);
/*輸出學號也用%s*/
}
void find(struct student stu[])
{
int flag=0;
int i,j;
sort(stu) /*;//stu[];)*/
printf(“the student of one score=90 and 前五名:\n”);
/*這兩句調換一下位置,不然輸出不太好*/
for(i=0;i5;i++)
{
int sum=0;
for(j=0;j4;j++)
if(stu[i].score[j]=90 )sum++;
if(sum)
{
flag=1;
printf(“%-8s%-8.2f%-8.2f%-8.2f%-8.2f%-8.2f%-8.2f\n”,stu[i].num,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].sum,stu[i].aver);
}
}
if(flag==0)
printf(” not exist!\n”);
/*這個判斷放在循環體之外,不然會輸出好多” not exist!”*/
}
另外,注意:
1.個班的學生成績最多35人。你的咋是固定35人捏?
2.第四點要求:根據用戶要求輸入課程號顯示該門課程成績在90以上且總分在前五的學生的 學號和各科成績,平均分和總分
你似乎沒有看清題意吧?是要用戶輸入課程號耶。
這些你自己應該知道怎麼做吧?
1、用C語言編寫一個程序計算自己的期末考試成績的總分。(要求各科成績從鍵盤
#includestdio.h
int main()
{ int n,i,s=0,x;
printf(“考了幾門功課?\n”);
scanf(“%d”,n);
printf(“請輸入%d門功課的成績: \n”);
for(i=0; in; i++)
{ scanf(“%d”,x);
s+=x;
}
printf(“總分是:%d\n”,s);
return 0;
}
原創文章,作者:HZATT,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/128181.html