number 2 plssssss help !!....using array.. turbo c..

create a program that will accept a number and determine if
it is a happy number or an unhappy number..

example:

enter a number : 7



7*7=49

then 4 and 9

4*4 and 9*9== 16 + 18 gives you 97

then 9 and 7

9*9 and 7*7 == 81 + 49 gives you 130

then 1 and 3

1*1 and 3*3 == 1 + 9 gives you 10

1*1 gives you 1



sample output:



7= 49= 16+81= 97= 81+49=130 =1+9=10 =1


"7 is a happy number"





. if the last number is 2 then the number being inputed is
not a happy number.

Answer Posted / y hussain reddy

void main()
{
int n;
int f(int);
printf("nter number");
scanf("%d",&n);
while(n>9)
{
n=f(n*n);
}
if(n==1)
printf("%d is happy number",n);
else
printf("%d is unhappy number",n);
}
int f(int n)
{
int s=0;
while(n)
{
s+=(int)pow(n%10);
n=n/10;
}
return s;
}

Is This Answer Correct ?    5 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is union in c?

626


What are the 4 types of functions?

561


Are pointers really faster than arrays?

552


write a programe to accept any two number and check the following condition using goto state ment.if a>b,print a & find whether it is even or odd and then print.and a

1445


List out few of the applications that make use of Multilinked Structures?

1277






What is function prototype?

603


what is the role you expect in software industry?

1645


Write a program to swap two numbers without using a temporary variable?

599


Which built-in library function can be used to match a patter from the string?

732


Explain what is wrong with this statement? Myname = ?robin?;

986


What is wrong with this declaration?

604


Why functions are used in c?

578


Explain pointers in c programming?

626


Which of the following operators is incorrect and why? ( >=, <=, <>, ==)

651


Explain what is wrong with this program statement?

614