www.3112.net > C语言函数 【问题描述】输入2个正整数m和n(m>=1,n<=1000),输出m~n之间...

C语言函数 【问题描述】输入2个正整数m和n(m>=1,n<=1000),输出m~n之间...

#include <stdio.h>int factorsum(int n){ int sum,i; for(i=1,sum=0;i<n;++i) { if(n%i==0) sum+=i; } return sum;}int main(void){ int m,n; while(scanf("%d , %d",&m,&n)==2) { for(;m<n;++m) { if(m==factorsum(m)) { printf("%d ",m); } } printf("\n"); } return 0;}

#include <stdio.h>int prime(int n){ int i; if(n<2) { return 0; } for(i=2;i*i<=n;++i) { if(n%i==0) return 0; } return 1;}int main(void){ int m,n,cnt,sum; while(scanf("%d , %d",&m,&n)==2) { for(cnt=sum=0;m<n;++m) { if(prime(m)) { cnt++; sum+=m; } } printf("count=%d,sum=%d\n",cnt,sum); } return 0;}

while(m>=1&&n<=10000&&m<=n) { for(i=1;i<=n;i++) if(fib(i)>=m&&fib(i)<=n) printf("%d ",fib(i)); break; }//加一句break;

#include "stdio.h" main() { int m,n,i; long int sum=1,sum1=1,sum2=1,t; printf("请输入m>n\n"); scanf("%d",&m); scanf("%d",&n); while(m { clrscr(); printf("请重新输入m,n\n"); scanf("%d",&m); scanf("%d",&n); } for(i=1;i sum=sum*i; for(i=1;i sum1=sum1*i; for(i=1;i sum2=sum2*i; t=sum/sum1*sum2; printf("m!/(m-n)!*n!=%ld",t); }

主要代码:for(i = m, i 评论0 0 0

int fib(int n) { int a=1,b=1,c,i; for(i=2;i<n;i++) { c=a; a+=b; b=c; if(a>10000)return 0; } return a; }

#include "stdio.h" void main() { int prime(int m); int m =0,n=0; scanf("%d,%d", &m,&n); int max = 0, min = 0; max = m > n? m:n; min = m> n?n:m; int i = 0,count = 0, sum = 0; for (i = min + 1; i < max; i++) { if (1 == prime(i)) { sum += i; count++; } }

#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h> int is(int number){ int d1=number/1%10; int d2=number/10%10; int d3=number/100%10; if(number==d1*d1*d1+d2*d2*d2+d3*d3*d3) { return 1; } else { return 0; }} int main(){

好久没弄C语言了,也不知道什么是水仙花数,你的程序应该是少了两个大括号导致的 换成下面的代码试试.没有大括号默认的执行范围是下面一行 也就是说你的循环只是作用在 gw=i%10;#include void main() { int m,n,gw,sw,bw,i; printf("输入两个正整数:"); scanf("%d%d",&m,&n); for(i=m;i { gw=i%10; bw=i/100; sw=i%100/10; if(i==gw*gw*gw+sw*sw*sw+bw*bw*bw) printf("%d\n",i); } }

#include "stdio.h" int factorsum(int n){ int temp=0; for(int i=1;i<=n/2;i++) { if(n%i==0) { temp+=i; } } return temp;} void main(){ int m,n; printf("请输入m,n(1<n<m<1000):\n"); scanf("%d",&m); scanf("%d",&n); printf("%d~%d间的完数有:\n",m,n); for(int i=m;i<=n;i++) { if(i==factorsum(i)) printf("%d\n",i); } }

相关搜索:

网站地图

All rights reserved Powered by www.3112.net

copyright ©right 2010-2021。
www.3112.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com