Check Whether a Number is Perfect or Not : C Program

Computer Science » C Program » Check Whether a Number is Perfect or Not

Program :

#include<stdio.h>
 
int main() 
{
   int num, i = 1, sum = 0;
 
   printf("nEnter a number : ");
   scanf("%d", &num);
 
   while (i < num) {
      if (num % i == 0) {
         sum = sum + i;
      }
      i++;
   }
 
   if (sum == num)
      printf("n%d is a perfect number.", i);
   else
      printf("n%d is not a perfect number.", i);
 
   return 0;
}

Output 1:

Enter a number : 6
6 is a perfect number.

Output 2:

Enter a number : 
5 is not a perfect number.
Subject Name : Computer Science
Exam Name : IIT GATE, UPSC ESE, RRB, SSC, DMRC, NMRC, BSNL, DRDO, ISRO, BARC, NIELIT
Posts Name : Assistant Engineer, Management Trainee, Junior Engineer, Technical Assistant
Computer Science Books

GATE 2023 Total InfoENGG DIPLOMAUGC NET Total Info
IES 2023 Total InfoPSUs 2022 Total InfoCSIR UGC NET Total Info
JAM 2023 Total InfoM TECH 2023 Total InfoRAILWAY 2022 Total Info

Related Posts

  • Check Whether a Number is Prime or Not : C ProgramComputer Science » C Program » Check Whether a Number is Prime or Not  Program : [php]#include<stdio.h> int main() { int num, i, count = 0; printf("nEnter a number :"); scanf("%d", &num); for (i = 2; i <= num / 2; i++) { if (num % i == 0) { count++; break; } } if (count == 0) printf("n%d is a prime number.", num); else printf("n%d is not a prime number.", num); return 0; }[/php] Output 1: [php]Enter a number : 5 5 is a prime number.[/php] Output 2: [php]Enter a number : 4 4 is not a prime number.[/php]
    Tags: program, check, number, output, computer, science, programs
  • Check if Number is Odd or Even : C ProgramComputer Science » C Program » Check if Number is Odd or Even Program : [php]#include<stdio.h> int main() { int n; printf("nEnter a number : "); scanf("%d",&n); if ( n%2 == 0 ) printf("n%d is an even number.", n); else printf("n%d is an odd number.", n); return 0; }[/php] Output 1: [php]Enter an number : 122 122 is an even number.[/php] Output 2: [php]Enter an number : 123 123 is an odd number.[/php]
    Tags: program, check, number, output, computer, science, programs
  • Check Whether a Number is Palindrome or Not : C ProgramComputer Science » C Program » Check Whether a Number is Palindrome or Not  Program : [php]#include <stdio.h> int main() { int n, reversedN = 0, remainder, originalN; printf("nEnter an integer : "); scanf("%d", &n); originalN = n; // reversed integer is stored in reversedN while (n != 0) { remainder = n % 10; reversedN = reversedN * 10 + remainder; n /= 10; } // palindrome if orignalN and reversedN are equal if (originalN == reversedN) printf("n%d is a palindrome.", originalN); else printf("n%d is not a palindrome.", originalN); return 0; }[/php] Output 1: [php]Enter an integer: 101 101 is a palindrome.[/php] Output 2: [php]Enter an integer: 102 102 is not a palindrome.[/php]
    Tags: program, check, number, output, computer, science, programs
  • Check Whether a Number is Armstrong or Not : C ProgramComputer Science » C Program » Check Whether a Number is Armstrong or Not  Program : [php]#include<stdio.h> int main() { int num, temp, sum = 0, rem; printf("nEnter a number : "); scanf("%d", &num); temp = num; while (num != 0) { rem = num % 10; sum = sum + (rem * rem * rem); num = num / 10; } if (temp == sum) printf("n%d is a amstrong number.", temp); else printf("n%d is not a amstrong number", temp); return (0); }[/php] Output 1: [php]Enter a number : 153 153 is a amstrong number.[/php] Output 2: [php]Enter a number : 150 150 is not a amstrong number[/php]
    Tags: program, check, number, output, computer, science, programs
  • Check if a Number is Divisible by 3 : C ProgramComputer Science » C Program » Check if a Number is Divisible by 3 Program : [php]#include<stdio.h> int main() { int number; printf("Enter a number : "); scanf("%d",&number); if ((number % 3) == 0) printf("n%d is a multiple of 3.",number); else printf("n%d is not a multiple of 3.",number); return 0; }[/php] Output 1: [php]Enter a number : 9 9 is a multiple of 3.[/php] Output 2: [php]Enter a number : 8 8 is not a multiple of 3.[/php]
    Tags: program, check, number, output, computer, science, programs

LEAVE A REPLY

Please enter your comment!
Please enter your name here