Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

1.

/*TO CHECK IF NUM IS HAPPY NUMBER OR NOT*/


#include<stdio.h>
int main()
{
int num,sum=0,rem;
printf("Enter the number:");
scanf("%d",&num);
while(sum!=1 && sum!=4)
{
sum=0;
while(num!=0)
{
rem=num%10;
sum+=(rem*rem);
num/=10;
}
num=sum;
}
if(sum==1)
printf("It is a Happy Number.");
else
printf("It is not a Happy Number.");
}
OUTPUT
------------
Enter the number:23
It is a Happy Number.

2./*TO CHECK IF NUM IS DISARIUM NUMBER OR NOT*/


#include <math.h>
#include<stdio.h>
int main()
{
int num,c=0,a,sum=0;
printf("Enter the number:");
scanf("%d",&num);
int temp=num;
int b=num;
while(temp!=0)
{
temp=temp/10;
c++;
}
while(c!=0)
{
a=num%10;
sum += pow(a,c);
num=num/10;
c--;
}
if(sum==b)
printf("it is a disarium number");
else
printf("it is not a disarium number");

}
OUTPUT
----------
Enter the number:175
it is a disarium number

3./*TO CHECK IF NUM IS HARSHAD NUMBER OR NOT*/


#include <math.h>
#include<stdio.h>
int main()
{
int n,a,sum=0;
printf("Enter the number:");
scanf("%d",&n);
int temp=n;
while(n!=0)
{
a=n%10;
sum+=a;
n/=10;
}
if(temp%sum==0)
printf("it is a harshad number");
else
printf("it is not a harshad number");

}
OUTPUT
--------------
Enter the number:156
it is a harshad number

4./*program to check if pronic or not */


#include <stdio.h>
void main()
{
int n,i,div;
printf("Enter a number:");
scanf("%d",&n);
for(i=1;i<n;i++)
{
if(i*(i+1)==n)
{
printf("is pronic");
break;
}
else
continue;
}
if(i==n)
{
printf("is not pronic");
}
}
OUTPUT
-------------
Enter a number:45
is not pronic

5.

You might also like