C Online Compiler
Example: ABUNDANT Number or Not in C using While loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// ABUNDANT Number or Not in C using While 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 int i = 1; while (i < number) { if (number % i == 0) sum += i; 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; }
12
Output
Clear
ADVERTISEMENTS