October 25, 2024
Chicago 12, Melborne City, USA
C#

Write a program to find and display numers


Write a program to find and display numers <= 1000 that satisfy the property: the number is equal to the sum of the numbers its divisor. Example 6 = 1 + 2 + 3

#include <stdio.h>
int main() {
  int n;
  int x;
    int sum = 0;
    int i;
    for ( i = 1; i < n ; i++) {
        if (n % i == 0) {
            sum += i; 
        }
    }
    return sum;
    for (x=1; x<=1000; x++) {
      if (x=sum){
          print("%d/n", sum);
      }
  }
}

I’m having an issue with the for loop because the variable n has not run from 1 to 1000. Can you help me find the error? (I’m a beginner and I have only learned about the for loop and if-else statements.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video