Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C Compiler.
- Code, Compile, Run and Debug C program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- int num;
- int sum = 0;
- int i; //Loop variable
- char keepGoing;
- // prompts user to enter a number
- printf("Enter a number between 100 and 10,000\n");
- scanf("%d", &num);
- //if number isnt within range
- while (num < 100 || num>10000) {
- printf("This number is outside the accepted range.\n");
- printf("Enter a number between 100 and 10,000\n");
- scanf("%d", &num);
- }
- keepGoing = 'y';
- sum = 0;
- //if number is within range
- if (num >= 100 && num <= 10000) {
- while (keepGoing == 'y') {
- for (i = 1; i < num; i++) {
- if (num%i == 0) {
- sum = i + sum;
- }
- if (num == sum) {
- printf("Number %d is perfect.\n", num);
- printf("Number of iterations are %d.\n", i);
- }
- else {
- printf("Number %d is not a perfect number.\n", num);
- printf("Number of iterations are %d.\n", i);
- }
- }
- printf("Do you want to continue? (y/n) ");
- scanf("%s", &keepGoing);
- if (keepGoing == 'n') {
- printf("Goodbye.\n");
- }
- else {
- printf("Enter a perfect number \n");
- scanf("%d", &num);
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement