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

will u give me old quesrion papers for aptitude for L & t info tech?

1 Answers   Hindustan, L&T,


how to print 212 as Twohundreds twelve plz provide me ans soon

1 Answers  


What are the types of c language?

0 Answers  


What is the use of gets and puts?

0 Answers  


Are the variables argc and argv are always local to main?

0 Answers  






Explain what is the benefit of using enum to declare a constant?

0 Answers  


Write a C program linear.c that creates a sequence of processes with a given length. By sequence it is meant that each created process has exactly one child. Let's look at some example outputs for the program. Here the entire process sequence consists of process 18181: Sara@dell:~/OSSS$ ./linear 1 Creating process sequence of length 1. 18181 begins the sequence. An example for a sequence of length three: Sara@dell:~/OSSS$ ./linear 3 Creating process sequence of length 3. 18233 begins the sequence. 18234 is child of 18233 18235 is child of 18234 ........ this is coad .... BUt i could not compleate it .....:( #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { int N; pid_t pid; int cont; if (argc != 2) { printf("Wrong number of command-line parameters!\n"); return 1; } N = atoi(argv[1]); printf("Creating process sequence of length %d.\n",N); printf("%d begins the sequence.\n",getpid()); /* What I have to do next ?????? */ }

0 Answers  


What is external variable in c?

0 Answers  


What is the process to create increment and decrement stamen in c?

0 Answers  


marge linklist

0 Answers   HCL,


Suggesting that there can be 62 seconds in a minute?

0 Answers  


In CMM or CMMI certified organizations,we assess only the standard software processes of the organization. We do not assess the organizations other functional departments like HR or Admin. Then how can we certify the entire organization as CMM level company?? We have assessed only software related activities. Right. There is no relation with other departments like Accounts, HR or Admin. Then how can we claim that the whole company is a CMM certified company?

1 Answers   Melstar,


Categories