sum+=goal[j]; j++; } } //judge the sum of factors and p the two values are equal. if (sum==p) { printf("%d its factors are ",p); for(int i=0;i<j;i++) { if(i==j-1) printf("%d \n",goal[i]); else printf("%d ",goal[i]); } } } return 0; }
#include<stdio.h> #define NUM 100 int main() { int goal[NUM];//array for factors. int sum=0; int N; scanf("%d",&N); for(int p=2;p<N;p++)//1 and N are not included. { // sum is different for every number // need to be set to 0 individually for every number sum = 0; int j=0; for(int i=1;i<p; i++) // i++ everytime { //get factors and put them into array. if (p%i==0) // changed while to if // while would keep executing forever { goal[j]=i;
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:758 |
【回文数(二)】 (C语言代码)浏览:728 |
十->二进制转换 (C语言代码)浏览:1291 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:994 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:672 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:466 |
有关字符,字符串的输入输出函数说明浏览:478 |
蓝桥杯历届试题-翻硬币 (C++代码)浏览:872 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:486 |
C二级辅导-求偶数和 (C语言代码)浏览:671 |