求用c语言编写程序

2024-11-15 05:47:55
推荐回答(3个)
回答1:

vc里面建立一个控制台程序,代码如下:
#include
#include
int
main()
{
int
len;
printf("请输入正方形的边长:");
while(scanf("%n",&len)){
printf("正方形的边长为:%d\n",len);
printf("正方形的表面积为:%d\n",len*len);
printf("正方形的体积为:%d\n",len*len*len);
printf("\n请输入正方形的边长:");
}
}
这段代码是计算正方形表面积和体积的,直接用记事本编写的,没有编译过,不知道有没错误,有错误你自己稍微修改下,大致是这样,我手头上没有vc,就不编译了

回答2:

#include

int
main
(void)
{

int
m,n,k;

printf
("输入M的值:\n");

scanf("%d",&m);

printf
("输入N的值:\n");

scanf("%d",&n);

int
k
=
m
/
n;

printf
("%d.%df",k,k) ;
//
一个%d
为K的值,第二个.d%
为小数点后K位

return
0;
}

我也初学者..
应该是这样编程吧.

回答3:

//程序可以成功运行,可以写入文件和屏幕,不懂得可以交流!
//希望kutpbpb的回答能对你有所帮助!!!
#include
#include
typedef
struct
grade
{
int
Eng;
int
Math;
int
Cg;
int
Pe;
float
avg;
}grade,*pgrade;
typedef
struct
user
{
char
name[20];
char
sno[20];
grade
score;
}user,*puser;
void
main()
{
FILE
*fp;
user
L[10];
int
i;
printf("\nPlease
Enter
the
stu
info:");
for(i=0;i
{
printf("\nEnter
the
%d
stu
information
:",i+1);
printf("\nEnter
name:");
scanf("%s",L[i].name);
printf("Enter
Sno:");
scanf("%s",L[i].sno);
printf("Enter
Eng
grade:");
scanf("%d",&L[i].score.Eng);
printf("Enter
Math
grade:");
scanf("%d",&L[i].score.Math);
printf("Enter
C
grade:");
scanf("%d",&L[i].score.Cg);
printf("Enter
PE
grade:");
scanf("%d",&L[i].score.Pe);
L[i].score.avg=(L[i].score.Eng+L[i].score.Math
+L[i].score.Cg+L[i].score.Pe)/4.0;
}
fp=fopen("a.txt","w");
for(i=0;i
{
fprintf(fp,"\nThe
%d
student
info:\nname:%s",i+1,L[i].name);
printf("\nThe
%d
student
info:\nname:%s",i+1,L[i].name);
fprintf(fp,"\nsno:%s
\nscore
:",L[i].sno);
printf("\nsno:%s
\nscore
:",L[i].sno);
fprintf(fp,"\nEng:
%5d\nMath:
%5d\nCg:
%5d\nPe:
%5d",L[i].score.Eng,
L[i].score.Math,L[i].score.Cg,L[i].score.Pe);
printf("\nEng:
%5d\nMath:
%5d\nCg:
%5d\nPe:
%5d",L[i].score.Eng,
L[i].score.Math,L[i].score.Cg,L[i].score.Pe);
fprintf(fp,"\navg:
%5.2lf",L[i].score.avg);
printf("\navg:
%5.2lf",L[i].score.avg);
}
fclose(fp);
}百度地图