C Online Compiler
Example: ABUNDANT Number or Not in C using For loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// ABUNDANT Number or Not in C using For loop #include <stdio.h> // It's the main function of the program int main() { int number, sum = 0; // Step-1 Take an input from the User printf("INPUT A NUMBER: "); scanf("%d", &number); // Step-2 Calculate the sum of divisors of the input number for (int i = 1; i < number; i++) { if (number % i == 0) sum += i; } // Step-3 Compare the input number with the sum of its divisors if (sum > number) { printf("\n%d IS AN ABUNDANT NUMBER", number); printf("\nABUNDANCE = %d\n", sum - number); } else printf("\n%d IS NOT AN ABUNDANT NUMBER!\n", number); return 0; }
16
Output
Clear
ADVERTISEMENTS