C Online Compiler
Example: HARSHAD Number or Not in C using While loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// HARSHAD Number or Not in C using While loop #include <stdio.h> // It's the main function of the program int main() { int num, sum = 0; // Step-1 Take an input from the User printf("INPUT A NUMBER: "); scanf("%d", &num); // Step-2 Store the input value into another variable int original = num; // Step-3 Use a loop to check the Harshad number while (original != 0) { sum += original % 10; original /= 10; } // Step-4 Compare the input value with the sum of divisors of the input value if (num % sum == 0) printf("\n%d IS A HARSHAD NUMBER\n", num); else printf("\n%d IS NOT A HARSHAD NUMBER\n", num); return 0; }
156
Output
Clear
ADVERTISEMENTS