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
Are pointers really faster than arrays?
What is the -> in c?
What does c value mean?
Where can I get an ansi-compatible lint?
When should I declare a function?
What is the difference between formatted&unformatted i/o functions?
Why isnt there a numbered, multi-level break statement to break out
Why do we use & in c?
What is variable in c example?
What are near, far and huge pointers?
What is array in c with example?
Can you please explain the difference between strcpy() and memcpy() function?
Can we declare variables anywhere in c?
What is function definition in c?
How does free() know explain how much memory to release?