Showing posts with label Loops. Show all posts
Showing posts with label Loops. Show all posts

C Program to Check whether a given Number is Perfect Number

C program to check whether a given number is perfect number


 C Program to Check whether a given Number is Perfect  Number

In this program, I have discussed about the C program to check whether a given number is perfect number

A number is called a perfect number if the sum of all the divisors of that number is equal to that number.
For example:- 6,,,,,,,, 1+2+3=6.

 
#include<stdio.h>
int main()
{ int n,sum=0,k,i;
printf("Enter the number:");
scanf("%d",&n);
k=n/2;
for(i=1;i<=k;i++)
{ if(n%i==0)
{ sum=sum+i;
}
}
if(n==sum)
{printf("Perfect Number !!");
}
else
printf("Not a perfect number !!");
}

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.


Enjoy programming in C.
,

C program to reverse a number.

C program to reverse a number

C program to reverse a number

 In this program, I have discussed about the C program to reverse a number


#include<stdio.h>
#include<math.h>
int main()
{ int n,k,a=0,rev=0;
printf("Enter the number");
scanf("%d",&n);
while(n>0)
{k=n%10;
n=n/10;
rev=(rev*10)+k;
}
printf("%d",rev);
}

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.
,

C program to print fibonacci series upto n terms

C program to print fibonacci series upto n terms

C program to print fibonacci series upto n terms


In this program, I have discussed about C program to print fibonacci series upto n terms.


#include<stdio.h>
int main()
{
int n,n1,n2,n3,count;
printf("Enter the no. of terms:");
scanf("%d",&n);
n1=0;n2=1;
printf("%d %d ",n1,n2);
count=2.5;
while(count<n)
{ n3= n1+n2;
count++;
printf("%d ",n3);
n1=n2;
n2=n3;
}
}


Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.
,

C Program to Check Armstrong Number


C Program to Check Armstrong Number

C Program to Check Armstrong Number

 In this program, I have discussed about the C program to check armstrong number. this program is solely made for 3 digit armstrong numbers.

#include<stdio.h>
{int main()
    {int s=0;k,n,r;
printf("Enter a number");
scanf("%d",&n);
k=n;
        while(n>0)
        { r=n%10;
            s=s+r*r*r;
            n=n/10;}
            if(k==s)
            {printf("Armstrong Number");}
            else
            {printf("Not Armstrong Number");
            }
        }
    }

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.

 

Copyright 2020 Programming in C All Right Reserved