c语言编写源程序内容,编程(C语言源程序代码)讲述.doc
已知 S=1+1/(1+2)+1/(1+2+3)+…+1/(1+2+3+…+N) ,當(dāng)N的值為50時(shí),求S的值。要求:按四舍五入的方式精確到小數(shù)點(diǎn)后第四位。
#include
#include
main()
{float s=0.0;
int n,t=0;
for(n=1;n<=50;n++)
{t=t+n;
s=s+1.0/t;
}
printf("%7.4f",s);
}1.9608把一張一元鈔票,換成一分、二分和五分硬幣,每種至少11枚,問(wèn)有多少種方案?
#include< stdio.h >
void main()
{int x,y,z,count=0;
for(x=11;x<=100; x++; )
{for(y=11;y<=50; y++; )
{ for(z=11;z<=20;z++)
{if(x+2*y+5*z==100)
printf(“x=%d,y=%d,z=%d”,x,y,z);
count++;
}
}
}
printf(“there are %d methods”,count);
}13“完數(shù)”:
一個(gè)數(shù)如果恰好等于它的所有真因子之和,這個(gè)數(shù)就稱為“完數(shù)”。例如,6的真因子為1,2,3,而6=1+2+3,因此,6是“完數(shù)”。求1000以內(nèi)的所有完數(shù)之和。
#include
main()
{int i,j,s=0,t;
for(i=2;i<=1000;i++)
{t=1;
for(j=2;j
if(i%j==0) t=t+j;
if(t==i) {printf("%4d",i);s=s+i;}
}
printf("\n%d",s);
}530下面的程序是求[200,800]之間最大的20個(gè)素?cái)?shù)之和。
程序:
#include
#include
void main()
{ int k=800,sum=0, n=0, j, yes;
while((k>=200)&&(n<20))
{yes=1 ;
for(j=2; j<=sqrt(k); j++)
if(k%j==0) {yes=0; break;}
if(yes)
{ printf(“%5d”,k);sum+=k; n++;
if(n%5==0) printf(“\n”);
}
k--;
}
printf("%d \n",sum);
}14510“同構(gòu)數(shù)”:
所謂“同構(gòu)數(shù)”是指這樣一個(gè)數(shù),它出現(xiàn)在它的平方數(shù)的右側(cè),例如5的平方是25,25的平方是625,故5和25都是同構(gòu)數(shù),求[2,1000]之間所有同構(gòu)數(shù)之和。(提示:若x是m位同構(gòu)數(shù),則x的平方除以10的m次方的余數(shù)就是x)
#include
#include
#include
main()
{ long s;
long k,n,sum=0,count=0;
clrscr();
for (n=2;n<=1000;n++)
{ if (n<10) k=10;
else if (n<100) k=100;
else k=1000;
s=n*n;
if (s%k==n) {count++;sum+=n;printf("%4d",n);}
}
printf("\n%5ld,%5ld",count,sum);
}1113倒勾股數(shù):
A,B,C是三個(gè)小于或等于300的正整數(shù),當(dāng)滿足1/A^2+1/B^2=1/C^2關(guān)系,并且A>B>C時(shí),稱為倒勾股數(shù)。求這樣的倒勾股數(shù)有多少組。填空完成程序,然后運(yùn)行程序得出正確結(jié)果。(答案填程序運(yùn)行結(jié)果,保留整數(shù)位)
#include
main()
{double a,b,c;
int count=0;
clrscr();
for( c=1;c<=300;c++)
for (b=c+1;b<=300;b++)
for (a=b+1;a<=300;a++)
if (1.0/(a*a)+1.0/(b*b)==1.0/(c*c) )
count=count+1 ;
printf("%d",
總結(jié)
以上是生活随笔為你收集整理的c语言编写源程序内容,编程(C语言源程序代码)讲述.doc的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: js使用正则实现表单验证
- 下一篇: jq 在字符串中,去掉指定的元素