一道大一计算机C语言编程题,急求答案,谢谢!

作者&投稿:闵畏 (若有异议请与网页底部的电邮联系)
一道大一计算机C语言编程题,急求答案,在线等,谢谢!~

#includeint main(){int n,a=2,i;long sum=0,t=0;scanf("%d",&n);for(i=1;i<=n;i++){ t=t*10+a; sum+=t;}printf("%ld
",sum.);return 0;}

//第3题
#include
#include
int main(void)
{
char f_name[24];
char str[100];
printf("please enther the file name:");
scanf("%s",str);
sprintf(f_name,"%s.txt",str);
FILE *fp=fopen(f_name,"w+");
printf("please enther the string:");
scanf("%s",str);
fprintf(fp,"%s%d",str,strlen(str));
return 0;
}
//第4题
#include
#include
#include
typedef struct {
int num;
char name[20];
int math;
int chin;
int eng;
int avg;
}student;
void cal_avg(student *stu)
{
int i=0;
for (i;i<5;i++)
{
stu[i].avg=(stu[i].chin+stu[i].math+stu[i].eng)/3;
}
}
int output(student *stu)
{
FILE *fp=fopen("stud.txt","w+");
if (fp==NULL)
{
printf("can't open file!");
return -1;
}
fwrite(stu,sizeof(student),5,fp);
return 1;
}
void input(student *stu)
{
int i=0;
for (i;i<5;i++)
{
stu[i].num=i+1;
printf("please enther the %dth student's name:",i+1);
scanf("%s",stu[i].name);
printf("please enther the %dth student's math grade:",i+1);
scanf("%d",&stu[i].math);
printf("please enther the %dth student's chin grade:",i+1);
scanf("%d",&stu[i].chin);
printf("please enther the %dth student's eng grade:",i+1);
scanf("%d",&stu[i].eng);
printf("/********************************************/
");
}
}
int main(void)
{
student stu[5];
input(stu);
cal_avg(stu);
output(stu);
return 0;
}

#include "stdafx.h"
void main(){
int a=1,b,c,d,e,f;
printf("请输入第一个数:");
scanf("%d",&b);
printf("请输入第二个数:");
scanf("%d",&c);
d=b>c?c:b;
for(int i=2;i<=d;i++){
if(b%i==0&&c%i==0){
a=i;
}
}
if(a==1){
printf("
没有公约数
");
}
else{
printf("
最大公约数为: %d
",a);
}
e=b>c?b:c;
for(int i=e;;i++){
if(i%b==0&&i%c==0){
f=i;
break;
}
}
printf("最小公倍数为: %d
",f);
}



#include<stdio.h>
void main()
{
int x,y,k,m,n,i;
x=1;
printf("请输入两个整数:");
scanf("%d%d",&m,&n);
if(m>n) k=n;
else k=m;
for(i=2;i<=k-1;i++)
{
if(m%i==0 &&n%i==0) x=i;
}
printf("最大公约数是%d\n",x);
y=(m*n)/x;
printf("最小公倍数是%d\n",y);
}

#include<stdio.h>
int main()
{
int a1,b1,y,t;
int a,b;
scanf("%d,%d",&a,&b);
if(a<b)
{
a1=b;
b1=a;

y=a1%b1;}
else
y=a1%b1;
while(y!=0)
{
a1=b1;
b1=y;
y=a1%b1;

}

printf("%d\n",b1);
printf("%d\n",a*b/b1);

return 0;
}


几道大一的C语言编程题
int b,c,d,e;b=0;c=0;d=0;e=0;\/ b是字母 c是数字 d是符号 e是空格*\/ fflush(stdin);printf("请输入一串东西:");while ((a=getchar())!='\\n'){ if(a>='a'&&a<='z'||a>='A'&&a<='Z')b++;else if(a>='0'&&a<='9')c++;else if(a=='')e++;else d++;...

大一c语言两道题目,帮忙写代码,在线等!
printf("恭喜一等奖\\n"); } else n=2; } if(n==2 || n==3) { if(s<10) { s++; printf("恭喜二等奖\\n"); } else n = 4; } if(n ==4 || n==5 || n==6)

大一C语言求解这四道题
第一题:include<stdio.h>int salary(int workTime){ if(workTime<0) printf("工作时间不能为负数!\\n"); else if(workTime<=160) return 5*workTime; else return 5*160+(workTime-160)*9;}int main(){ int workTime; printf("请输入一个月的工作小时数:"); sca...

请问这道C语言题,如何做,详解。 我是大一的,请问C语言如何学好?
-2在计算机中表示为1111 1111 1111 1110,用上面取反加1 的方法试下,很容易看出1111 1111 1111 1110表示的就是-2。65535,楼上已经说得很清楚了。

几道大一计算机c语言模拟考试题目,求分析一下
i++]的 选择B p为指针,A和D选项int* 和int之间无法赋值,C选项左值错误,即常量不能取地址 选择C Point函数参数为指针,修改参数p的指向位置等同于修改原值,所以p+=3等同于p指针偏移3位,即p[3],所以结果为d 选择B C语言中,不允许赋值给表达式,即(b=4)=3的写法是错误的 ...

大一C语言追加50分求解这几道
if (BMI<18) printf("\\n您的体质指数属于过轻,请加强营养和锻炼。\\n");else if(BMI<=24.99)printf("\\n您的体质指数属于正常,请继续保持。\\n\\n");else if(BMI<=27.99)printf("\\n您的体质指数属于超重,请注意饮食,并加强锻炼。\\n\\n");else printf("\\n您的体质指数属于肥胖,...

【大一C语言】下列程序段当a的值为014和0x14时的执行结果分别是...
if (a=0xa | a > 12) \/\/先算 10==a 因为a=11所以这个表达式是假的,即为0 然后与八进制的011即十进制的9进行\/\/与运算,显然0 & 9的值还是0,所以执行后面的else运算if (011&10 == a) printf("%d!\\n", a);else printf("right!%d\\n", a);else printf("wrong %d\\n", a);...

大一c语言,在考试,求答案,三道题
a)-1)printf("最大的数是:%d",a[i]);}第三题:int a[10] = {\/\/里面写10个分数}int score;int b;score = (a[0]+a[1]...+a[9])\/10;printf("平均数是:%d",score);for(int i=0;i<10;i++){if(a[i]<60){b++;}}printf("合格率是:%d",b\/10);PS:C语言不复杂的...

大一c语言的一道题
num1,num2 num4声明为Int吧

大一C语言求解这几道题
void main(){ float w,h,bmi;char ch='Y';while((ch!='N')&&(ch!='n')){ printf("输入体重(kg)、身高(米)\\n");scanf("%f%f",&w,&h);getchar();bmi=w\/(h*h);if(bmi<18) printf("你过轻,需要补充营养\\n");else { if(bmi>=18&&bmi<25) printf("正常\\n");else ...

昌黎县13195747055: 关于c程序的题 - 几道大一的C语言编程题1.编写一个程序实现如下功能:计算1~10
战软贝洛: 第一题:#include "stdio.h" void main() { int a,b,sum=0; for(a=0;a main() { char a; int b,c,d,e; b=0;c=0;d=0;e=0; /* b是字母 c是数字 d是符号 e是空格*/ fflush(stdin); printf(...

昌黎县13195747055: 我是一位学习计算机的大一学生,我有一道简单的c语言题目,不知道谁能帮我解答? -
战软贝洛: max = a>b?a:b;max = max>c?max:c;补充:大一了还解决不了这种问题....

昌黎县13195747055: 大一c语言编程题,急求代码.正确立刻采纳!谢谢 -
战软贝洛: \0',b); } return 0;b[i] = i; b[j] ;{ fun(b);*') { for(j printf("%s\n";!=&nbsp!= NULL) ; ++i) { if(b[i] == 'fun(char '\0'#include + 1]; void *b) { /* */ int i,j; for(i = ++j) b[j] 0; = b[j&nbsp!= ' --i; } } /* */ } int main() { char b[1024]; while(gets(b)

昌黎县13195747055: c语言编程题,急!
战软贝洛: 包含命令拼错了~~ 直接把算法写到输出那里~ 定义的float类型,记得scanf的时候是%f,不是%d #include&lt;stdio.h&gt; main() { float a,b,c,x,y,z; a=0.8; b=1.0; c=3.5; scanf("%f%f%f",&amp;x,&amp;y,&amp;z); printf("%f\n",a*x+b*y+c*z); }

昌黎县13195747055: 急求一道c语言编程题的答案 C语言高手帮忙看下
战软贝洛: #include<stdio.h> main() { int solve(int n); int t; scanf("%d",&t); if(t<=1) printf("0"); else printf("%d",solve(t)); printf("\n"); } int solve(int n) { int a,b,c; a=0; b=1; do { c=a+b; a=b; b=c; if(c>=n) break; }while(1); return a; }

昌黎县13195747055: 求助:一道C语言程序的题,急!初学还不怎么会,谢谢,多给分 -
战软贝洛: main(){ int a[10],b[10],c[10]; int i; int *p; printf("please input a[10]:\n"); p=a; for(i=0;i<10;i++) scanf("%d...

昌黎县13195747055: 急求一道c语言编程题 -
战软贝洛: #include void fun(int m) { char c; if(m==0) { } else { c=m%10+'0'; fun(m/10); printf("%c",c); } } void main() { int i; char c; printf("输入整数i:"); scanf("%d",&i); c=i%10+'0'; fun(i/10); printf("%c\n",c); }

昌黎县13195747055: 急求解一道C程序题(20)有以下程序#include<st
战软贝洛: 答案确实应该为B. 当i=0时,第一次进入循环,由于S[0]!=0,i++ 当i=1时,第二次进入循环,由于S[1]!=0,i++ 当i=2时,第三次进入循环,由于S[2]!=0,i++ 当i=3时,第四次进入循环,由于S[3]=x,满足条件,所以n++,n=1 当i=4时,第五次进入循环,由于S[4]=y,满足条件,所以n++,n=2 当i=5时,由于s[5]=0,所以退出循环,n=2

昌黎县13195747055: 急!求解一道c语言编程题(详细点) -
战软贝洛: int x=10,y=14,ifor (i=0;x>8;y=++i) //最后一句要循环一次以后才能执行printf... //输出10 14,并且x变成9,因为x--先输出后变化for ....... //这里先++i,i=1,然后y也变成1printf... //这次输出9,1,并且x变成8for .... 这次不满足x>8了,退出循环...所以是10 14 9 1 D

昌黎县13195747055: 求解一道C语言编程题!!...
战软贝洛: #define N 3 #define M 2 main() { int a[N][M],b[M][N]; int i,j; printf("please intput element of the %d*%d matrix\n",N,M); for(i=0;i<N;i++) for(j=0;j<M;j++) scanf("%d",&a[i][j]); printf("matrix a:\n"); for(i=0;i<N;i++) { for(j=0;j<M;j++) printf("%-3d",a[i]...

你可能想看的相关专题

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网