ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
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.
 Question Submitted By :: Hmmm
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
#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 ?    4 Yes 0 No
Swapnil Chhajer
 
  Re: 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
# 2
29
 
Is This Answer Correct ?    1 Yes 0 No
Wqw
 
 
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
Please list all the unary and binary operators in C.  1
what does the following function print? func(int i) { if(i%2)return 0; eale return 1; } main() { int =3; i=func(i); i=func(i); printf("%d",i);} TCS8
plz answer..... a program that reads non-negative integer and computes and prints its factorial  2
why i join syntel? Syntel12
main() {int a=200*200/100; printf("%d",a); } TCS7
#include main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); break; case j: printf("BAD"); break; } } ME5
Explain what?s happening in the first constructor: public class c{ public c(string a) : this() {;}; public c() {;} } How is this construct useful?  1
6)swap(int x,y) { int temp; temp=x; x=y; y=temp; } main() { int x=2;y=3; swap(x,y); } after calling swap ,what are yhe values x&y?  2
the code is::::: if(condition) printf("hello"); else printf("world"); WHAT WILL BE THE CONDITION IN IF IN SUCH A WAY THAT BOTH HELLO AND WORLD ARE PRINTED IN A SINGLE ATTEMPT?????? SINGLE ATTEMPT IN THE SENSE... IT MUST FIRST PRINT "HELLO" AND IT MUST GO TO ELSE PART AND PRINT "WORLD"..... NO LOOPS, RECURSION ARE ALLOWED........................ IBM9
x=2,y=6,z=6 x=y==z; printf(%d",x) HCL8
What will be the result of the following program? main() { char p[]="String"; int x=0; if(p=="String") { printf("Pass 1"); if(p[sizeof(p)-2]=='g') printf("Pass 2"); else printf("Fail 2"); } else { printf("Fail 1"); if(p[sizeof(p)-2]=='g') printf("Pass 2"); else printf("Fail 2"); } } a) Pass 1, Pass 2 b) Fail 1, Fail 2 c) Pass 1, Fail 2 d) Fail 1, Pass 2 e) syntax error during compilation IBM10
Program to find the value of e raised to power x using while loop N-Tech3
what is the function of void main()?  6
Look at the Code: #include<string.h> void main() { char s1[]="abcd"; char s2[10]; char s3[]="efgh"; int i; clrscr(); i=strcmp(strcat(s3,ctrcpy(s2,s1))strcat(s3,"abcd")); printf("%d",i); } What will be the output? A)No output B) A Non Integer C)0 D) Garbage Accenture5
how to find a 5th bit is set in c program IBM3
writw a program to insert an element in the begning of a doubly linked list  1
what is difference between overriding and overloading?  1
which header file contains main() function in c? TCS3
What are advantages and disadvantages of recursive calling ? HP11
Go through the following code sinippet char a[20]; a="Hello Orcale Test"; will this compile? Oracle3
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com