你点击原文,就分你小鱼干
计算机语言的学习基础是C语言。掌握好C语言就尤为重要。
1
题目:
计算所有三位水仙花数之和。所谓水仙花数是指所有位上数字的立方和等于该数,如:153= 1+5+3
输出结果的形式为:
s=1234
参考程序:
#include
void PRINT(long s)
{
FILE *out;
printf("s=%ld\n,s);
if( (out=fopen("result. dat”,' w+”)) !=NULL)
{
fprintf (out, "S=s%ld",s):
fclose (out) ;
}
}
void main()
long s=0:
int i,a,b,c:
for(i1oo: iN1000i+)
{
a=i%10;
b=i/10%10;
c=i/100;
if (a*a*atb*b*b+cжc*c=i) s+=i:
}
PRINT(s);
}
2
题目:
根据下式计算s的值(要求使用循环实现):
说明:结果保留4位小数。
输出结果的形式为:
s=12.4567
参考程序:
#include
void PRINT (double s)
{
FILE *out;
printf(" s=%.4fn",s):
if ((out-fopen(" result. dat","w+")) !=NULL)
fprintf(out," s=%. 4fg",s);
fclose (out) ;
}
void main()
{
double s;
int i;
s=l;
for(i=2;i<=100;i=i+2)
s=s*1.0*i/(i-1)*i/(i+1) ;
PRINT(s) :
}
3
题目:
计算1~ 2018之间所有3或5的倍数的和(要求使用循环实现)。
输出结果的形式为:
s=123456
#include
void PRINT (1ong s)
{
FILE *out;
printf(" s=%ld\n",s);
if((out=fopen(" result. dat", "w+")) !=NULL)
{
fprintf(out,'”s=%ldg' ,s) ;
fclose (out) ;
}
}
void main()
{
long s=0;
int i;
for(i=1;i<2018;i++)
if(i%3==0 || 1%5==0)
s=s+i;
PRINT(s);
}
希望阿程发的这些题目能够帮助到大家!
投稿邮箱:[email protected]. com
编辑|排版|佘义伟
审校|杨有浩
责任编辑|张元莹 梁星雨
宿州学院信息工程学院学生会出品
如需转载请询问后台