Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

happy numbers program

+1 vote
asked Jun 18, 2019 by anonymous

1 Answer

0 votes
answered Jun 19, 2019 by anonymous
#include<stdio.h>

#include<conio.h>

int num,sum[500],prevsum,i,j,digit,res,orig,sums;

int square(int n);

main()

{

clrscr();

printf("Please enter a number: ");

scanf("%i",&orig);

num=orig;

for(i=1;i<=500;i++)

{

while(num>0)

{

digit=num%10;

num=num/10;

sums=sums+(digit*digit);

}

sum[i]=num;

prevsum=sum[i];

num=sum[i];

if((prevsum==1)||(prevsum==4))

break;

}

for(i=1;sum[i]>0;i++)

{

printf("%i--",sum[j]);

}

if(prevsum==1)

printf("%i is Happy number.",orig);

else if(prevsum==4)

printf("%i belongs to the unhappy numbers.",orig);

getche();

return 0;

}

HOPE YOUR PROBLEM IS CLEAR!!
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...