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
Explain what are the different file extensions involved when programming in c?
Is it possible to execute code even after the program exits the main() function?
write a program to find out prime number using sieve case?
program for reversing a selected line word by word when multiple lines are given without using strrev
What is the use of getchar functions?
largest Of three Number using without if condition?
How can you increase the size of a dynamically allocated array?
What is typedef struct in c?
Are there constructors in c?
WRITE A PROGRAM TO MERGE TWO SORTED ARRAY USING MERGE SORT TECHNIQUE..
What does & mean in scanf?
How do you list a file’s date and time?
How do I round numbers?
How does normalization of huge pointer works?
How do you search data in a data file using random access method?