In this tutorial we will learn how to write a program that print all Happy number between one to hundred(1 to 100).we will write a program to print all integers till N.
C program code
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,num,x,temp,sum=0;
printf("\n Enter number till what you want happy numbers to be displayed:\n ");
scanf("%d",&x);
for(a=1;a<=x;a++)
{
sum=0;
num=a;
temp=num;
while(sum!=1 && sum!=4)
{
sum=0;
while(num>0)
{
b=num%10;
sum+=(b*b);
num=num/10;
}
num=sum;
}
if(sum==1)
{
printf("\n %d",a);
}
}
getch();
}
OUTPUT 1:
OUTPUT 2:
In first output, the value of input number is 35
The Happy numbers between 1 to 35 is
1, 7, 10, 13, 19, 23, 28, 31, 32
In second output,the value of input number is 25
The Happy numbers between 1 to 25 is
1, 7, 10, 13, 19, 23
The Happy numbers between 1 to 35 is
1, 7, 10, 13, 19, 23, 28, 31, 32
In second output,the value of input number is 25
The Happy numbers between 1 to 25 is
1, 7, 10, 13, 19, 23
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.
Created by-- HARSH CHAUHAN
No comments:
Post a Comment