#include <stdio.h> int main(){ int N; scanf("%d",&N); int number[N]; int i,j,sum=0; for(i=0;i<N;i++){ number[i]=i+4; sum=0; for(j=1;j<number[i];j++){ if(number[i]%j==0){ sum+=j; if(number[i]==sum){ printf("%d\n",number[i]); } } } } return 0; } 各位大佬,能不能帮忙看看,当我键入N=1000的时候,会多一个24出来,其他的结果和题目给的例子是符合的,想知道是哪里出了问题
#include <stdio.h> int main() { int n = 0; scanf("%d", &n); int arr[100] = { 0 }; for (int i = 6; i <= n; i++) { int c = 0,d=0; for (int j = i; j >= 2; j--) { if (i % j == 0) { arr[c++] = i / j; d += (i / j); } } if (d == i) { printf("%d its factors are ", i); for (int e = 0; e < c; e++) { printf("%d ", arr[e]); } printf("\n"); } } return 0; } 就这样
#include<stdio.h> void isFac(int num) { int sum=1; for(int i=2;i<num;i++) if(num%i==0) sum+=i; if(num==sum) { printf("%d its factors are ",num); for(int i=1;i<num;i++) if(num%i==0) printf("%d ",i); printf("\n"); } } int main() { int N; scanf("%d",&N); for(int i=2;i<=N;i++) isFac(i); return 0; }
#include <stdio.h> int main(){ int sum=1, i=2,y=2,N=0; scanf("%d",&N); for(i;i<=N;i++){ sum=1; y=2; for(y;y<i;y++){ if(i%y==0&&i!=y){ sum+=y; } } if(i==sum){ printf("%d its factors are",i); y=1; for(y;y<i;y++){ if(i%y==0){ printf(" %d",y); } } printf("\n"); } } }
#include<stdio.h> int main() { int i,j,k=0,a[1001],n=0; scanf("%d",&i); for(j=1;j<i;j++) { if(i%j==0) { k+=j; a[n]=j; n++; } } if(i==k) { printf("%d its factors are",i); for(j=0;j<n;j++) printf(" %d",a[j]); } else printf("its is not "); return 0; } 我这个错哪了呀?
王文萱 2023-03-27 22:39:41 |
怎么没有i循环
愿祥FIRM 2023-04-16 16:40:26 |
他把i设置成了输入的那个变量1000了,后面又想输出一个关于i的循环,那肯定不行呗
蓼蓝 2023-05-31 09:46:28 |
少了一层循环,每次只能判断一个数,题目要求是判断某个数以下所有数
675 2023-06-06 21:56:26 |
#include<stdio.h> int main() { int str[1000]; //定义一个数组用来储存因子 int flag = 0,N,Sn = 0; //flag--作为数组的下标 Sn用以求因子之和 N作为键盘键入的接收数据 scanf_s("%d", &N); for (int i = 1; i <= N; i++) //最外面的循环是为了遍历所有小于等于N的数, { for (int j = 1; j < i; j++) //求因子的循环 { if (i % j == 0) { str[flag] = j; flag++; } } for (int k = 0; k < flag; k++) //求和循环 { Sn += str[k]; } if (i == Sn) //完数对比 { printf("%d its factors are ", i); for (int m = 0; m < flag; m++) { printf("%d ", str[m]); } printf(" "); Sn = 0; flag = 0; } else { Sn = 0; flag = 0; } } return 0; }
#include<stdio.h> void wanshu(int n) { int i,j=0; int b=0; int a[n]; for(i=1;i<n;i++) { if(n%i==0) { a[j]=i; b+=a[j]; j++; } } if(b==n)//判断是否为完数 { printf("%d its factors are ",n); for(i=0;i<j;i++) { printf("%d ",a[i]); a[i]=0; } printf("\n"); } } int main() { int i; int n; scanf("%d",&n); for(i=2;i<=n;i++) { wanshu(i); } return 0; }
#include <stdio.h> void print(int n,int i) { for (i = 1; i < n; i++) { int a = n % i; if (a == 0) printf("%d ", i); } } int main() { int n = 0; scanf("%d", &n); int i = 0; int add=0; for (i = 1; i < n; i++) { int a =n%i; if (a == 0) add = add + i; } if (add == n) printf("%d its factors are ",n); print(n, i); return 0; }为什么没通过呢?
三进制小数 (C++代码)(第11位大于1.5才能进位)浏览:1203 |
C语言训练-尼科彻斯定理 (C语言代码)。。。内含证明定理浏览:2140 |
C二级辅导-等差数列 (C语言代码)浏览:628 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:644 |
WU-蓝桥杯算法提高VIP-Quadratic Equation (C++代码)浏览:1808 |
C语言程序设计教程(第三版)课后习题6.6 (C++代码)浏览:649 |
IP判断 (C语言代码)浏览:819 |
【计算直线的交点数】 (C语言代码)浏览:1501 |
C语言训练-自由落体问题 (C语言代码)浏览:650 |
DNA (C语言代码)浏览:564 |