2题
void fun(int a[],int n,int max,int d)
{
d = 0;
max = a[0];
for (int i = 1; i < n; i++)
{
max = a[i] > max a[i] ,d++: max;
}
}
3题
void minsert(int a[], int j, int m, int n)
{
for (int i = n; i >= j; i--)
{
a[i + 1] = a[i];
}
a[j] = m;
}
4题
int fun(double x [], int n);
int main()
{
double x[100] = { 1001,1002,1003,1004,1005,1006,1007,1008 };
printf("平均值以上的实数个数为: %d\n", fun(x, 8));
return 0;
}
int fun(double x [], int n)
{
int j, c = 0;
double xa = 0;
for (j = 0; j < n; j++)
{
xa += x[j] / n;
}
printf("平均值为%f\n", xa);
for (j = 0; j < n; j++)
{
if(x[j]>=xa)
{
c++;
}
}
return c;
}
晕报告也要人教啊,我教你写
一、程序主要功能∶
某校规定,学习成绩超过全班平均成绩的%10者得第一等奖,学习成绩超过全班平均成绩的%5者得第二等奖,某班有30名学生,请编写一个C语言程序,实现下列功能:
1,输入全班学生成绩(学生用学号代表);
2,分别输出得一等奖和二等奖同学的学号和成绩。
二、程序设计说明:(算法设计思路与流程图)
在脑海中不知道怎么表达谢谢。
三、实验结果与结论:我太聪明了怎么变态的题目都做出来了哈哈狂笑哈哈还是狂笑。
四、实验中遇到的问题及解决方法:
由于本人聪颖过人,程序未遇任何错误,有何不足之处还望不吝赐教。
#include<stdioh>
int max(int x,int y,int z)
{
int t;
t=x>yx:y;
t=t>zt:z;
return(t);
}
int min(int x ,int y,int z)
{
int t;
t=x<yx:y;
t=t<zt:z;
return(t);
}
int aver(int x ,int y,int z)
{
int t;
t=(x+y+z)/3;
return(t);
}
void main()
{ int x,y,z,a,b,c;
scanf("%d,%d,%d",&x,&y,&z);
a=(max)(x,y,z);
b=(min)(x,y,z);
c=(aver)(x,y,z);
printf("%d,%d,%d\n",a,b,c);
}
建议改成:
#include<stdioh>
int max(int x,int y,int z)
{
int t;
t=x>yx:y;
t=t>zt:z;
return(t);
}
int min(int x ,int y,int z)
{
int t;
t=x<yx:y;
t=t<zt:z;
return(t);
}
float aver(int x ,int y,int z)
{
int t;
t=(float)((x+y+z)/30);
return(t);
}
void main()
{ int x,y,z,a,b;float c;
scanf("%d,%d,%d",&x,&y,&z);
a=(max)(x,y,z);
b=(min)(x,y,z);
c=(aver)(x,y,z);
printf("max=%d\nmin=%d\naver=%g\n",a,b,c);
}
#include<stdioh>
#include<mathh>
#include<stdlibh>
#define N 2
typedef struct student
{
int num;
char name;
int score[3];
}Student;
void print(Student myclass[],int length)
{
int i=0,sum=0,sum1=0,sum2=0,max=0;
for(i=0;i<length;i++)
{
printf("num:%d name:%s 数学:%d 英语:%d 自然:%d 平均=%2lf 总分=%d\n",
myclass[i]num,myclass[i]name,myclass[i]score[0],myclass[i]score[1],myclass[i]score[2],(myclass[i]score[0]+myclass[i]score[1]+myclass[i]score[2])/30,(myclass[i]score[0]+myclass[i]score[1]+myclass[i]score[2]));
sum=sum+myclass[i]score[0];
sum1=sum1+myclass[i]score[1];
sum2=sum2+myclass[i]score[2];
if((myclass[i]score[0]+myclass[i]score[1]+myclass[i]score[2])>max)
max=i;
}
printf("平均 数学:%d 英语:%d 自然:%d\n",sum/length,sum1/length,sum2/length);
printf("最高:num:%d name:%s 数学:%d 英语:%d 自然:%d 平均=%2lf 总分=%d\n",
myclass[max]num,myclass[max]name,myclass[max]score[0],myclass[max]score[1],myclass[max]score[2],(myclass[max]score[0]+myclass[max]score[1]+myclass[max]score[2])/30,(myclass[max]score[0]+myclass[max]score[1]+myclass[max]score[2]));
}
void input(Student myclass[],int length)
{
int i=0;
for(i=0;i<length;i++)
{
printf("请输入第%d个学生的信息\n",i+1);
printf("学号");
scanf("%d",&myclass[i]num);
myclass[i]name=(char)malloc(sizeof(char)20);
printf("姓名");
scanf("%s",myclass[i]name);
printf("数学");
scanf("%d",&myclass[i]score[0]);
printf("英语");
scanf("%d",&myclass[i]score[1]);
printf("自然");
scanf("%d",&myclass[i]score[2]);
}
}
void main()
{
Student myclass[N];
input(myclass,N);
print(myclass,N);
}
可以满足楼主的要求,望采纳!!
我来说说楼主的一些问题,首先你的那段程序,函数应该在外面声明,在main函数里面调用,其次是函数要传入结构体的参数,大概就是这些主要的问题,当然还有一些小的问题,自己找吧!!!
#include<stdioh>
int sum(int n)
{
if(n==1) return 1;
else
return sum(n-1)+n;
}
void main()
{
int n;
scanf("%d",&n);
printf("%d\n",sum(n));
}
c语言程序设计第三版指导答案
附录F 课后题参考答案
习 题 1
11 填空题
1.函数
2.主函数main();主函数main() 3.主函数main() 4.函数首部;函数体 5.{;}
6.顺序结构;选择结构;循环结构 7.c;obj;exe
12 思考题
1.答:结构化程序设计是指,为使程序具有一个合理的结构以保证程序正确性而规定的一套如何进行程序设计的原则。顺序结构,选择结构,循环结构
2.答:算法是对具体问题求解步骤的一种描述。计算机算法的表达工具通常采用以下几种方法:①用自然语言表示算法;②用流程图表示算法;③用伪代码表示算法;④用程序设计语言表示算法。
3.略 4.略 5.略 13 编程题 1.答:
#include "stdioh" main()
{ float a=10, b=20, h=5, s; s=(a+b)h/2;
printf("s=%f " , s ); }
2.答:
#include "stdioh"
main()
{ printf(""); printf(" hello world "); printf(""); }
习 题 2
21 单选题
DBDCA DCABB CA
22 填空题
1.2000000
2.1;0500000
3.9;2 4.6 5.100;d 6.(1)20
(2)0
(3)60 7.(1)10;6;4
(2)6;9;15
(3)3;60;83
8.55或 '7'
9.x=4;y=6;z=3;m=463
23 改错题(略)
习 题 3
31 单选题
BDABC ADCAC BBA
32 填空题
1.3 2.261 3.10
4.2, 1;互换a,b的值 5.66 6.003 7.7
8.50,4,c=3<Enter>
9.i=10,j=20<Enter>
10. (1)65 (2)65,A (3)314,12346
(4)3141600e+000,1234560e+002 (5)8765432100 (6)8765432e+003
11.a=2b=5x=88y=7634c1=65c2=97 12.%d/%d;%d/%d=%2f\n
33 改错题(略) 34 编程题
1.答:
#include "stdioh" main() {
int x,y;
scanf("%d%d",&x,&y); printf("\t\tx\ty\n");
printf("十进制数\t%d\t%d\n",x,y); printf("八进制数\t%o\t%o\n",x,y); printf("十六进制数\t%X\t%x\n",x,y); }
2.答:
#include "stdioh" main() {
char ch;
printf("请输入一个大写英文字母"); scanf("%c",&ch);
printf("大写英文字母是%c\n",ch); printf("它的前导字符是%c\n",ch-1); printf("它的后续字符是%c\n",ch+1); }
3.答:
#include "stdioh" main() {
int x,a,b,c,y;
printf("请输入一个三位整数\n"); scanf("%d",&x); a=x/100;
b=(x-a100)/10; c=x%10;
y=c100+b10+a;
printf("反向输出该整数:%d\n",y); } }
4.答:
#include "stdioh" main()
{ int hour;
double salary, salaryday;
scanf("%d,%lf", &hour, &salaryday );
salary=hoursalaryday- hoursalaryday01;
printf("%82lf\n", salary); }
5.答:
#include "stdioh" main() {
int a,b,c,t;
printf("请输入三个整数\n"); scanf("%d%d%d",&a,&b,&c);
printf("交换前a=%d,b=%d,c=%d\n",a,b,c); t=a;a=c;c=b;b=t;
printf("交换后a=%d,b=%d,c=%d\n",a,b,c); }
习 题 4
41 单选题
BADDD ACBBB BA
42 填空题
1.1
2.(1)a>0 || b>0
(2)x>0 && x<=10 (3)a==15 && b==15 && c==15
(4)p<a || p<b || p<c
3.(1)0 (2)1 (3)1 (4)0 (5)1
4.c=1 5.-4 6.1 7.5, 0, 3 8.5 9.123
10.( cvb= ='y'||cvb= ='Y')&&(work>=3||college=='y'|| college=='Y')&&age<=35
43 改错题(略) 44 编程题
1.答
#include "stdioh"
#include "mathh" main() {
double a,b,c,p,area;
scanf("%lf%lf%lf",&a,&b,&c);
printf("三角形的三边为:%llf,%1lf,%1lf\n",a,b,c); if (a+b>c&&a+c>b&&b+c>a) {p=(a+b+c)/2;
area=sqrt(p(p-a)(p-b)(p-c));
printf("三角形的面积为%2lf\n",area); } else
printf("不能构成三角形\n"); }
2.答:
#include "stdioh" main()
{ int x,y;
scanf("%d,%d",&x,&y); if(xx+yy>1000)
printf("%d\n",(xx+yy)/100); else
printf("%d\n",x+y); }
3.答:
#include "stdioh" #include "mathh" main()
{ double x,y;
scanf("%lf",&x); if(x<-2) y=xx-sin(x); else if (x<=2) y=pow(2,x)+x; else y=sqrt(xx+x+1);
printf("x=%2lf y=%2lf\n",x,y); }
4.答:
#include "stdioh" main( )
{ long ge,shi,qian,wan,x; scanf("%ld",&x); wan=x/10000;
qian=x%10000/1000; shi=x%100/10;
ge=x%10;
if (ge==wan&&shi==qian) /个位等于万位并且十位等于千位/ printf("this number is a huiwen\n"); else
printf("this number is not a huiwen\n");
}
5.答:
#include "stdioh" main()
{ float p,w,s,d,f;
scanf("%f,%,%f",p,s,w); if (s>3000) d=015 else if( s>=2000) d=01; else if(s>=1000) d=008; else if(s>=500) d=005; else if(s>=250) d=002; else d=0 f=pws(1-d); printf("%f",f); }
6.答:
#include "stdioh" main()
{ int year,money; char x;
printf("是否是本公司产品(y/n):"); scanf("%c",&x);
if(x=='y'||x=='Y')
{printf("产品使用的年限:"); scanf("%d",&year);
if(year<=1) money=0;
else if(year<8) money=50; else money=100;
printf("产品保修额是:%d\n",money);
}
else
{ money=200;
printf("不是本公司产品,产品保修额是:%d\n",money); } }
7.答:
#include "stdioh" main()
{ int money,num1,num2;
printf("请输入取款额(≤2000):"); scanf("%d",&money);
if(money>2000) printf("请输入取款额数≤2000!\n"); else if(money%50==0) { num1=money/100; num2=(money-num1100)/50; printf("需支付100元:%d张\n",num1); printf("需支付50元:%d张\n",num2); } else printf("输入钱数必须是50的倍数!\n"); }
习 题 5
51 单选题
CDABA ABDDB DBCB
52 填空题
1.2 0 2.333
3.(1)i<10 或 i<=9 (2)j%3!=0
4.(1)flag(float)k/(k+1) 或10flagk/(k+1) (2)flag=-flag 5.(1)max=x
(2)x!=-1 (3)scanf("%d", &x)
6.(1)x<=9或x<10
(2)y=9-x
53 改错题(略) 54 编程题
1.答:
(1)for循环,其他略
#include "stdioh"
main()
{ int i,s=0;
for(i=1;i<=100;i++) s+=ii;
printf("%d\n",s); }
(2)for循环,其他略
#include "stdioh" main()
{ int i=1,p=1; double s=1; do {
s+=10/p; p=++i;
}while(10/p>1e-6); printf("%lf",s); }
2.答:
#include "stdioh" main()
{ int m,n,t,a,b;
scanf("%d,%d" ,&m,&n) if (m<n)
{ t=m m=n n=t } a=m; b=n; t=m%n while(t)
{ m=n n=t t=m%n;} printf("%d",n); }
3.答:
#include "stdioh" main()
{ int x,y,s=1;
scanf("%d,%d",&x,&y) for( y>0 y--)s=x
printf("%d,%d,%d\n ",s%10,s/10%10,s/100%10); }
4.答:
#include "stdioh" main()
{ int x,y,z;
for( x=1 x<20 x++) for( y=1 y<33 y++) { z=100-x-y
if ((z%3)==0 &&(5x+3y+z/3)==100) printf("x=%d,y=%d,z=%d\n",x,y,z) } }
5.答: (a)
#include "stdioh" main()
{ int j,k
for( j=1 j<=4 j++)
{ for(k=1;k<=4-j;k++)printf(" "); printf("") printf("\n") } }
(b)
#include "stdioh" main()
{ int j,k
for( j=1 j<=4 j++)
{for(k=1;k<=4-j;k++)printf(" "); for(k=1 k<=2j-1 k++) printf("") printf("\n") } }
6.答:
程序分析:利用for循环控制在100~999之间,对每个数分解出个位、十位、百位。
#include <stdioh> main() { int i,j,k,n; printf("water flower'number is:"); for(n=100;n<1000;n++) { i=n/100;/分解出百位/ j=n/10%10;/分解出十位/ k=n%10;/分解出个位/ if(n==iii+jjj+kkk) { printf("%-5d",n); } } printf("\n"); }
7.答:
#include <stdioh> main() { int x; for(x=1000;x>=3;x--) if(x%3==1&&x%5==2&&x%7==3) {
printf("该校的学生人数是:%d人\n",x); break; } }
8.答:
#include <stdioh> main() { int x=12,i=1; while(1)
{ if((x+20+i)==2(x+i)) break; i++; } printf("小明母亲在%d年后比小明的年龄大一倍\n",i); printf("那时小明年龄是:%d岁,小明母亲年龄是:%d岁\n",x+i,x+20+i); }
习 题 6
61 单选题
DBCCB BDC
C语言程序设计教程(第3版)
278
62 填空题
1.c 2.60 3.1000 10 4.16
63 编程题
1.答:
#include "stdioh" #include "mathh"
#define F(a) aa+ sqrt(3aa+2a+1) main()
{ float x, f;
scanf("%f", &x );
f=45/F(exp(x))+F(cos(x))+F(sqrt(x))/F(xx) printf("%f\n", f); }
习 题 7
71 单选题
BCADA CCCDA BCBDB
72 填空题
1.(1)2 3 4 5 (2)10010 (3)QuickC
(4)10000 01000 00100 00010 00001 (5)Language
(6)Language Programming 2.(1)j+=2 (2)a[i]>a[j] 3.(1)i=1 (2)x[i-1]
73 改错题(略) 74 编程题
1.答:
#define N 10
#include "stdioh" main()
{ int a[N]={1,2,3,4,5,6,7,8,9,10,osum=0, qsum=0,j; for(j=0;j<10;j++)
if( j%2) qsum+=a[j];
else osum+=a[j];
printf("osum=%d,qsum=%d\n", osum,qsum); }
2.答:
#define N 10
#include "stdioh" main()
{ int a[N]={10,20,30,40,50,60,70,80,90}, j, k, x; scanf("%d",&x); for(j=0;j<N;j++)
if (x<a[j]) break; if(j==N) a[N-1]=x; else
{for(k=N-1; k>j; k--) a[k]=a[k-1]; a[j]=x;}
for(j=0;j<N;j++)
printf("%d ",a[j]); }
3.答:
#define M 3
#include "stdioh" main()
{ int a[M][M]={{1,2,3},{2,4,5},{3,5,6}},j,k,flag=1;; for( j=0;j<M;j++)
for(k=0;k<M;k++) if (a[j][k]!=a[k][j]) { flag=0; break;} if (flag) printf("ok"); else printf("NO"); }
4.答:
#include "stdioh" #include "stringh" main()
{ char c1[10],c2[10],j; gets(c1); gets(c2);
for(j=0; (c1[j]==c2[j]) && c1[j] && c2[j]; j++); if (c1[j]>c2[j]) printf("%d\n",1); if (c1[j]<c2[j]) printf("%d\n",-1); if (c1[j]==c2[j]) printf("%d\n",0); }
5.答:
#include "stdioh" #include "stringh" #define M 3 #define N 80 main()
{ char a[M][N],j,k,n[5]={0}; for(j=0;j<M;j++) gets(a[j]);
for(j=0;j<M;j++)
for(k=0;a[j][k];k++)
if( a[j][k]>='A' && a[j][k]<='Z') n[0]++;
else if (a[j][k]>='a' && a[j][k]<='z') n[1]++; else if (a[j][k]>='0' && a[j][k]<='9') n[2]++; else if (a[j][k]==' ' ) n[3]++; else n[4]++;
for(j=0;j<5;j++) printf("%4d", n[j]); }
习 题 8
81 单选题
DBDAC BACCC
82 填空题
1.(1)2, 1 (2)10#30# (3)FOUR, P (4)60
2.(1)49
(2)2
(3)2
(4)
(5)
83 改错题(略) 84 编程题
1.答:
#include "stdioh"
main()
{ int n1,n2,n3,t; int p1,p2,p3;
printf("please input 3 number:n1,n2,n3:"); scanf("%d,%d,%d",&n1,&n2,&n3); p1=&n1;
p2=&n2; p3=&n3;
if(p1> p2) { t=p1;p1=p2;p2=t;}
if(p1>p3) { t=p1;p1=p3;p3=t;} if(p2>p3) { t=p2;p2=p3;p3=t;}
printf("the sorted numbers are:%d,%d,%d\n",n1,n2,n3); }
2.答:
#include "stdioh" #define N 3 main()
{ int a[N],p=a; for(;p-a<N; p++) scanf("%d",p); p=a+N-1;
for(;p-a>=0; p--) printf("%d ",p); }
3.答:
#include "stdioh" main()
{ int a[10];
int j,minl=0,maxl=0; for(j=0;j<10;j++)
scanf("%d", a+j); for(j=0;j<10;j++)
{ if(a[maxl]<(a+j)) maxl=j; if(a[minl]>(a+j)) minl=j; }
j=a[0]; a[0]=a[minl];a[minl]=j; j=a[9];a[9]=a[maxl];a[maxl]=j; for(j=0;j<10;j++) printf("%d ", (a+j)); }
4.答:
输入阵列如下: 1 2 3 4 5 6 7 8 9 10 11 12 输出阵列如下:
12 11 10 9 8 7 6 5 4 3 2 1
#define M 3
#define N 4
#include "stdioh" main()
{ int a[M][N]={1,2,3,4,5,6,7,8,9,10,11,12},k,j,p=&a[0][0],t; for(k=0,j=MN-1;k<j;k++,j--)
{ t=(p+k); (p+k)=(p+j); (p+j)=t;} for (k=0 k<M k++) { for(j=0 j<N j++)
printf("%4d ",a[k][j]); printf("\n");
} }
5.答:
#include "stdioh" main() {
int len;
char str[20],p=str;
printf("please input a string:\n"); scanf("%s",str); len=0;
while(p!='\0') {
len++; p++; }
printf("the string has %d characters\n",len); }
6.答:
#include "stringh" #include "stdioh" main() {
char str1[5],ch[5][20],k,t,j,c; void sort(char ); for(k=0;k<5;k++) {str1[k]=ch[k]; gets(str1[k]);} for(k=0;k<7;k++)
{ t=k;
for(j=k+1;j<5;j++) if(strcmp((str1+t),(str1+j))>0) t=j; c=(str1+t);
(str1+t)=(str1+k) (str1+k)=c }
for(k=0;k<5;k++) puts(str1[k]); }
习 题 9
91 单选题
CBBAD DBCCD DCABC BCCBA DCDAB
92 填空题
1.120 2.x 3.3,2,2,3 4.fac /i 5.8,17 6.9 7.10/(ii) 8.
fun-in:30,20,10 fun-end:1015,35,1050 10,20,30 9.012345 10.93636 11.(1)r+b[k] (2)x
12.7 5 3 1 9 13.15
14.(1)x (2)t 15.(1)'\0' (2)n++ 16.024
93 改错题(略) 94 编程题
1.答:
void zhuan( )
{ char ch;
while((ch=getchar())!='\n')
{ if(ch>='a' && ch<='z') ch=ch-32; putchar(ch); } }
2.答:
double expp(int n) { int k, fac=1; double sum=1;
for(k=1; k<=n; k++) { fac=k;
sum+=10/fac }
return(sum); }
3.答:
int xy3( int x, int y)
{ int k, num=1;
for(k=1;k<=y k++) num=x
num=num%1000 return num }
4.答:
int age( int n) { int c;
if(n==1) c=10
else c=age(n-1)+2 return c }
5.答:
#include "stdioh"
main()
{ int a,b,c,d;
void fun(int a,int b,int c, int d); scanf("%d%d",&a,&b); fun(a,b,&c,&d);
printf("%d %d",c,d);
}
void fun(int a,int b,int c, int d) { if (b)
{ c=a/b; d=a%b;} }
6.答:
#include "stdioh"
main(int argc,char argv[]) { int k;
printf("argc=%d\n",argc); for (k=1;k<argc; k++) printf("%s\n",argv[k]); }
习 题 10
101 单选题
CDBBB BBBAD CCBDC
102 填空题
1.所有结构体成员所占存储空间的总和 2.与占用存储空间最大的那个成员相等
附录F 课后题参考答案
285
3.(1)struct satype (2)3 (3)saa (4)9 (5)psa=&sa 4.80 5.struct node 6.0
103 编程题
1.答:
#include "stdioh"
struct student {
long num;
char name[20]; char sex; float score; }; main()
{ struct student s[20], temp; int j,k, man=0, woman=0;
float summan=0,sumwoman=0, aveman, avewoman; for(k=0; k<20; k++)
{ scanf("%ld %s %c%f",&s[k]num,s[k]name,&s[k]sex,&s[k]score); if(s[k]sex=='m')
{ summan+=s[k]score; man++;} else
{ sumwoman+=s[k]score;woman++ } }
aveman=summan/man;
avewoman=sumwoman/woman;
printf("%d\t%f\t%d\t%f\n",man,aveman,woman,avewoman); for(k=0; k<19; k++)
for(j=0;j<20-k;j++)
if(s[j]score<s[j+1]score)
{ temp=s[j];s[j]=s[j+1];s[j+1]=temp;} printf("the sorted numbers:\n"); for(k=0;k<20;k++)
printf("%ld\t%s\t%c\t%51f\n",s[k]num,s[k]name,s[k]sex,s[k]score); }
习 题 11
111 单选题
BADD
112 填空题
1.3d3d330 2.(1)28
(2)20 (3)0 (4)--9
3.(1)251
(2)42
(3)209
(4)–295 (5)848
习 题 12
121 单选题
BCDCA ADA
122 填空题
1.rewind(文件指针) 2."d1dat","rb" 3.stdin
4.文本文件;二进制文件 5.(1)"w"
(2)str[i]--32
(3)"r"
6.fopen 7.Hello 8.(1)"r"
(2)fgetc(fp)
(3)time++
C语言程序设计实验与习题指导课后程序设计答案
P18
(1)
#include<stdioh> int main(void) { intcelsius,fahr; fahr=150; celsius=5fahr/9-532/9; printf("fahr=%d,celsius=%d\n",fahr,celsius); return 0; }
(2)
#include<stdioh> int main(void) { intcelsius,fahr; celsius=26; fahr=9celsius/5+32; printf("celsius=%d,fahr=%d\n",celsius,fahr); return 0; }
(3)
#include<stdioh> int main(void) { intaverage,math,eng,comp; math=87; eng=72; comp=93; average=(math+eng+comp)/3; printf("math=%d,eng=%d,comp=%d,average=%d\n",math,eng,comp,average); return 0; }
(4)
#include<stdioh> int main(void) { intn,a,b,c; n=152
c=n%10;
b=(n/10)%10; a=n/100;
printf("整数%d的个位数字是%d,十位数字是%d,百位数字是%d\n",n,c,b,a); return 0;
}
P27
(1)
#include<stdioh> #include<mathh> int main(void) { intcelsius,fahr; printf("Enter celsius:"); scanf("%d",&celsius); fahr=9celsius/5+32; printf("fahr%d\n",fahr); return 0; }
(2)
#include<stdioh> #include<mathh> int main(void) { intmoney,year; doublerate,interest; printf("Enter money,year,rate:"); scanf("%d%d%lf",&money,&year,&rate); interest=moneypow(1+rate,year)-money; printf("interest=%2f\n",interest); return 0; }
(3)
#include<stdioh> #include<mathh> int main(void) { doublex,y; printf("Enter x:"); scanf("%lf",&x);
if(x<0){ y=pow(x+1,2)+2x+1/x; } else{ y=sqrt(x); }
printf("y=f(%f)=%2f\n",x,y); return 0;
}
(4)
#include<stdioh> int main(void) { intx,y; printf("Enter num1:"); scanf("%d",&x); printf("Enter num2:"); scanf("%d",&y); printf("%d+%d=%d\n",x,y,x+y); printf("%d-%d=%d\n",x,y,x-y); printf("%d%d=%d\n",x,y,xy); printf("%d/%d=%d\n",x,y,x/y); printf("%d%%%d=%d\n",x,y,x%y); return 0; }
10的阶乘
#include<stdioh> int main(void) { inti,n,product; printf("Enter n:"); scanf("%d",&n); product=1; for(i=1;i<=n;i++){ product=producti; } printf("product=%d\n",product); return 0; }
//mainc文件
#include<stdioh>
#include<stdlibh>
#define BufLen 20
#define KeChengCount 3
typedef struct tagStuInfor
{
char xh[BufLen]; //学号
char xm[BufLen]; //姓名
char kchm[KeChengCount][BufLen]; //课程名
float pshchj[KeChengCount]; //平时成绩
float kshchj[KeChengCount]; //考试成绩
float zpchj[KeChengCount]; //总评成绩
float zf;
}StudentInformation;
typedef struct tagBookInfor
{
char shm[BufLen]; //书名
float dj; //单价
}BookInformation;
void shurustu();
void zongfen();
void shuchumaxmin();
void sortbook();
void freeall();
//学生数,书数
int xshsh,shsh;
StudentInformation ptstu=NULL;
BookInformation ptbook=NULL;
int main()
{
char in[]="datatxt",out[]="T_datatxt";
int i;
float chjs[6],zf;
FILE fin,fout;
printf("250这个数字太不好了,能换成350吗?\n\n");
shurustu();
zongfen();
shuchumaxmin();
printf("请输入书数:");
scanf("%d",&shsh);
ptbook=(BookInformation)calloc(shsh,sizeof(BookInformation));
for(i=0;i<shsh;i++)
{
printf("请输入第%d本书的书名:",i+1);
scanf("%s",ptbook[i]shm);
printf("请输入第%d本书的单价:",i+1);
scanf("%f",&ptbook[i]dj);
}
printf("\n");
sortbook();
printf("按书的单价升序排序后的结果:\n书名\t单价\n");
for(i=0;i<shsh;i++)
{
printf("%s\t%2f\n",ptbook[i]shm,ptbook[i]dj);
}
fin=fopen(in,"r");
fout=fopen(out,"w");
while(!feof(fin))
{
for(i=0;i<6;i++)
{
fscanf(fin,"%f",&chjs[i]);
}
zf=02(chjs[0]+chjs[1]+chjs[2])+08(chjs[3]+chjs[4]+chjs[5]);
printf("%2f\n",zf);
fprintf(fout,"%2f\r\n",zf);
}
printf("\n");
fclose(fin);
fclose(fout);
freeall();
system("PAUSE");
return EXIT_SUCCESS;
}
void shurustu()
{
int i;
printf("请输入学生的个数:");
scanf("%d",&xshsh);
ptstu=(StudentInformation)calloc(xshsh,sizeof(StudentInformation));
for(i=0;i<xshsh;i++)
{
strcpy(ptstu[i]kchm[0],"C语言");
strcpy(ptstu[i]kchm[1],"高等数学");
strcpy(ptstu[i]kchm[2],"英语");
printf("请输入第%d个学生的学号:",i+1);
scanf("%s",ptstu[i]xh);
printf("请输入第%d个学生的姓名:",i+1);
scanf("%s",ptstu[i]xm);
printf("请输入第%d个学生的C语言课程的平时成绩和考试成绩:",i+1);
scanf("%f %f",&ptstu[i]pshchj[0],&ptstu[i]kshchj[0]);
printf("请输入第%d个学生的高等数学课程的平时成绩和考试成绩:",i+1);
scanf("%f %f",&ptstu[i]pshchj[1],&ptstu[i]kshchj[1]);
printf("请输入第%d个学生的英语课程的平时成绩和考试成绩:",i+1);
scanf("%f %f",&ptstu[i]pshchj[2],&ptstu[i]kshchj[2]);
}
printf("\n");
}
void zongfen()
{
int i;
for(i=0;i<xshsh;i++)
{
ptstu[i]zpchj[0]=02ptstu[i]pshchj[0]+08ptstu[i]kshchj[0];
ptstu[i]zpchj[1]=02ptstu[i]pshchj[1]+08ptstu[i]kshchj[1];
ptstu[i]zpchj[2]=02ptstu[i]pshchj[2]+08ptstu[i]kshchj[2];
ptstu[i]zf=ptstu[i]zpchj[0]+ptstu[i]zpchj[1]+ptstu[i]zpchj[2];
printf("%s的%s,%s,%s的总评成绩是:",ptstu[i]xm,ptstu[i]kchm[0],ptstu[i]kchm[1],ptstu[i]kchm[2]);
printf("%2f,%2f,%2f\n",ptstu[i]zpchj[0],ptstu[i]zpchj[1],ptstu[i]zpchj[2]);
printf("%s的总分是:%2f\n",ptstu[i]xm,ptstu[i]zf);
}
printf("\n");
}
void shuchumaxmin()
{
int i,min,max;
min=max=0;
for(i=1;i<xshsh;i++)
{
if(ptstu[i]zf<ptstu[min]zf)
{
min=i;
}
if(ptstu[i]zf>ptstu[max]zf)
{
max=i;
}
}
printf("总分最高的学生的信息:\n学号\t姓名\t");
printf("%s(平时)\t%s(平时)\t%s(平时)",ptstu[max]kchm[0],ptstu[max]kchm[1],ptstu[max]kchm[2]);
printf("\t%s(考试)\t%s(考试)\t%s(考试)\t总分\n",ptstu[max]kchm[0],ptstu[max]kchm[1],ptstu[max]kchm[2]);
printf("%s\t%s\t",ptstu[max]xh,ptstu[max]xm);
printf("%2f\t%2f\t%2f\t",ptstu[max]pshchj[0],ptstu[max]pshchj[1],ptstu[max]pshchj[2]);
printf("%2f\t%2f\t%2f\t%2f\n\n",ptstu[max]kshchj[0],ptstu[max]kshchj[1],ptstu[max]kshchj[2],ptstu[max]zf);
printf("总分最低的学生的信息:\n学号\t姓名\t");
printf("%s(平时)\t%s(平时)\t%s(平时)",ptstu[min]kchm[0],ptstu[min]kchm[1],ptstu[min]kchm[2]);
printf("\t%s(考试)\t%s(考试)\t%s(考试)\t总分\n",ptstu[min]kchm[0],ptstu[min]kchm[1],ptstu[min]kchm[2]);
printf("%s\t%s\t",ptstu[min]xh,ptstu[min]xm);
printf("%2f\t%2f\t%2f\t",ptstu[min]pshchj[0],ptstu[min]pshchj[1],ptstu[min]pshchj[2]);
printf("%2f\t%2f\t%2f\t%2f\n\n",ptstu[min]kshchj[0],ptstu[min]kshchj[1],ptstu[min]kshchj[2],ptstu[min]zf);
}
void sortbook()
{
int i,j,min;
BookInformation t;
for(i=0;i<shsh-1;i++)
{
min=i;
for(j=i+1;j<shsh;j++)
{
if(ptbook[j]dj<ptbook[min]dj)
{
min=j;
}
}
t=ptbook[i];
ptbook[i]=ptbook[min];
ptbook[min]=t;
}
}
void freeall()
{
if(NULL!=ptstu)
{
free(ptstu);
}
if(NULL!=ptbook)
{
free(ptbook);
}
}
//datatxt文件
50 65 70 88 97 80
66 87 95 46 88 97
77 82 65 58 91 58
78 87 91 48 66 70
以上就是关于求做C语言程序设计实验题 求求了!有重谢全部的内容,包括:求做C语言程序设计实验题 求求了!有重谢、c语言程序实验报告;、c语言程序设计课后习题解答与实验指导等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)