9 Mar 2013

perfect_number








/*
 program to check whether a given no. is a ""perfect no."" or not.


a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself


The first perfect number is 6

*/




#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,s=0;
cout<<"Enter the number:";
cin>>a;
cout<<"The factors of "<<a<<" are as follows:"<<endl;
for(b=1;b<a;b++)
{
a%b;
if(a%b==0)
{cout<<b<<endl;
s+=b;
}
}
if(s==a)
cout<<a<<" is  a perfect number.";
else
cout<<a<<" is not a perfect number.";
getch();
}

Categories: ,

Related Posts:

  • Fibonacci series /*       program to generate Fibonacci series in C++.  */   #include<iostream.h>#include<conio.h>int main(){clrscr();unsigned long first,second,third,n;first=0; second=… Read More
  • Prime_Composite /* program to check entered number is prime or composite....   */ #include<iostream.h> #include<conio.h> void main() { int n,i=2,a=0; clrscr(); cout<<"Enter th number=… Read More
  • pattern_nested loops /* program in c to print following pattern... &  &  &  &  &  &  &    &  &  &  &  &       … Read More
  • Inverse_matrix /*   program to find inverse of a matrix...   */ #include<stdio.h> int main() {   int a[3][3],i,j;   float determinant=0;   printf("Enter the 9 elements of matrix: "… Read More
  • pattern_rectangle /* program to print following pattern *********************** *                     * *                     * *&… Read More

0 comments:

Post a Comment

Copyright © 2025 UPgradeCODING | Powered by Blogger