
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C program to find if the given number is perfect number or not
Perfect number is the number; whose sum of factors is equal to 2*number.
Algorithm
An algorithm is explained below −
START Step 1: declare int variables and initialized result=0. Step 2: read number at runtime. Step 3: for loop i=1;i<=number;i++ Condition satisfies i. if(number%i==0) ii. result=result+i; Step 4: checking the sum of factors. i. if(result==2*number) ii. print perfect number iii. else print not perfect number STOP
Program
Following is the C program to find if the given number is perfect number or not −
#include<stdio.h> int main(){ int number,i,result=0;//declare variables and initialize result to 0 printf("enter the number:"); scanf("%d",&number); for(i=1;i<=number;i++){ if(number%i==0) result=result+i; } if(result==2*number) //checking the sum of factors==2*number printf("perfect number"); else printf("not perfect number"); }
Output
The output is given below −
enter the number:28 perfect number enter the number:46 not perfect number
- Related Articles
- Swift Program to Check if the given number is Perfect number or not
- C Program to find the given number is strong or not
- Swift Program to find the given number is strong or not
- Program to check whether the given number is Buzz Number or not in C++
- Write a Python program to find if a number is strong number or not
- Java program to find if the given number is positive or negative
- Find if the given number is present in the infinite sequence or not in C++
- Check if the given number is Ore number or not in Python
- C# Program to check if a number is prime or not
- Check if given number is Emirp Number or not in Python
- Swift Program to Check whether a number is a Perfect Cube or not
- Check if a given number is sparse or not in C++
- Swift Program to Check If a Number is Spy number or not
- Program to check whether given number is Narcissistic number or not in Python
- Python Program to Check if a Number is a Perfect Number

Advertisements