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
What is union in c?
What are the 4 types of functions?
Are pointers really faster than arrays?
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
List out few of the applications that make use of Multilinked Structures?
What is function prototype?
what is the role you expect in software industry?
Write a program to swap two numbers without using a temporary variable?
Which built-in library function can be used to match a patter from the string?
Explain what is wrong with this statement? Myname = ?robin?;
What is wrong with this declaration?
Why functions are used in c?
Explain pointers in c programming?
Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
Explain what is wrong with this program statement?