您好,欢迎来到意榕旅游网。
搜索
您的当前位置:首页C语言简单程序

C语言简单程序

来源:意榕旅游网
【1】:求方程5X-4Y=2,在|X|<=100,|Y|<=50内的整数解中|X|+|Y|最大值。 86 #include void main() { int x,y,max,a,t; max=0;

for(x=-100;x<=100;x++) { if((5*x-2)%4!=0) continue; y=(5*x-2)/4; if(y<-50||y>50) continue; if(y<0) y=-1*y; if(x<0) x=-1*x; a=x+y; if(a>max) { t=a; a =max; max=t; } }

printf(\"The max is %d \}

第一次修改: #include void main() { int x,y,max,a; max=0;

for(x=-100;x<=100;x++) { y=(5*x-2)/4; if((5*x-2)%4!=0||y<-50||y>50) continue; if(y<0) y=-1*y; if(x<0) x=-1*x; a=x+y; max=a>max?a:max; }

printf(\"The max is %d \}

设某四位数的各位数字的平方和等于100,共有多少个这种四位数? 49 #include void main() {

int a,b,c,d,n=0; for(a=1;a<=9;a++)

for(b=0;b<=9;b++) for(c=0;c<=9;c++)

for(d=0;d<=9;d++)

if(a*a+b*b+c*c+d*d==100) ++n; printf(\"the num is %d\}

“水仙花数”是指这样的数,其各位数字的立方和等于该数本身,如: 153=1^3+5^3+3^3。求100至999的范围内所有水仙花数的个数和它们之和。4, 1301 #include void main() {

int a,b,c,sum=0,n=0; for(a=1;a<=9;a++)

for(b=0;b<=9;b++) for(c=0;c<=9;c++)

if(a*a*a+b*b*b+c*c*c==100*a+10*b+c) {++n;

sum=sum+100*a+10*b+c; } printf(\"the num is %d\\n\printf(\"the sum is %d\}

#include void main() {

int a,b,c,n=0;

for(a=1;a<=9;a++)

for(b=0;b<=9;b++) for(c=0;c<=9;c++)

if(a*100+b*10+c<968&&a==c) ++n; printf(\"the num is %d\}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- yrrf.cn 版权所有 赣ICP备2024042794号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务