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
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 |
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 |
how to use enum datatype?Please explain me?
#include main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf(" %d",*p); *p = 10; printf(" %d %d",i,*p); c = (int*) calloc(2); printf(" %d ",*c); }
How do you print an address?
How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?
2 Answers Aricent, Manipal University,
.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }
How the processor registers can be used in C ?
A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.
what is const volatile?
Given a piece of code int x[10]; int *ab; ab=x; To access the 6th element of the array which of the following is incorrect? (A) *(x+5) (B) x[5] (C) ab[5] (D) *(*ab+5} .
in b=6.6/a+(2*a+(3*c)/a*d)/(2/n); which operation will be performed first a) 6.6/a b) 2*a c) 3*c d) 2/n
What is an expression?
main() { int a=0; if(a=0) printf("Ramco Systems\n"); printf("India\n"); } output?