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.

Answers were Sorted based on User's Feedback



number 2 plssssss help !!....using array.. turbo c.. create a program that will accept a number a..

Answer / swapnil chhajer

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int happyNumber(int n)
{
char temp[10];
itoa(n,temp,10);
int len=strlen(temp);
int ret,sum=0,i;

if(n==1)
return 1;
else if(n==4)
return 0;
else
{
for(i=0;i<len;i++)
sum += (temp[i]-48)*(temp[i]-48);
ret = happyNumber(sum);
}

return ret;
}


int main()
{
int n;
printf("Enter the number : ");
scanf("%d",&n);
if(happyNumber(n) == 1)
printf("\n\n%d is a HAPPY NUMBER",n);
else
printf("\n\n%d is NOT A HAPPY NUMBER",n);

fflush(stdin);
getchar();
return 0;
}

Is This Answer Correct ?    6 Yes 3 No

number 2 plssssss help !!....using array.. turbo c.. create a program that will accept a number a..

Answer / 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

number 2 plssssss help !!....using array.. turbo c.. create a program that will accept a number a..

Answer / wqw

29

Is This Answer Correct ?    3 Yes 3 No

Post New Answer

More C Interview Questions

Write a routine that prints out a 2-D array in spiral order!

1 Answers   Lucent,


Does sprintf put null character?

0 Answers  


What are header files? What are their uses?

0 Answers  


Which weighs more, a gram of feathers or a gram of gold?

2 Answers  


what is the value of b if a=5; b=++a + ++a

31 Answers   Infosys, TCS, Tech Mahindra,






What are structure types in C?

0 Answers  


What is the difference between text and binary i/o?

0 Answers  


What are the ways to a null pointer can use in c programming language?

0 Answers  


main() { enum{red,green,blue=6,white}; pf("%d%d%d%d", red,green,blue,white); return 0; } a)0 1 6 2 b)0 1 6 7 c)Compilation error d)None of the above

6 Answers  


List at least 10 sorting methods indicating their average case complexity, worst case complexity and best case complexity.

0 Answers   Ignou,


main() { int i = 10; printf(" %d %d %d \n", ++i, i++, ++i); }

10 Answers   TCS, Vector,


what is the output of the code and how? main() { int *ptr,x; x=sizeof(ptr); printf("%d",x); }

1 Answers  


Categories