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
 
 


 

Back to Questions Page
 
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.
Rank Answer Posted By  
 Question Submitted By :: Hmmm
I also faced this Question!!   © ALL Interview .com
Answer
#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;
}
 
0
Swapnil Chhajer
 
 
Answer
29
 
0
Wqw
 
 
Question
plssssss help !!....using array.. turbo c..


create a program that will accept number of words to be
consored.

.a word must not exceed 10 characters long
.the text to be entered will be no longer than 200 characters
.there will be no 10 words

example:

enter number of words to be censor: 5

enter words to censor:

windows
office
microsoft
bill
gates

enter text to censor:

bill gates founded microsoft and makes office and windows


sample output:

<consored> <censored> founded <censored> and makes
<censored> and <censored>
Rank Answer Posted By  
 Question Submitted By :: Hmmm
I also faced this Question!!   © ALL Interview .com
Answer
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
  int nocw,i,j,flag=0;
  char
cenWords[20][12],text[205],temp[12],finalText[450]={'\0'};

  printf("Enter number of words to be censor : ");
  scanf("%d",&nocw);

  printf("\nEnter words to be censor : ");
  for(i=0;i<nocw;i++)
                     scanf("%s",cenWords[i]);
                     
  fflush(stdin);
  printf("\nEnter text to censor : ");
  gets(text);
  
  for(i=0;i<strlen(text);i++)
  {
     j=0;
     flag=0;
     while(!(text[i]==' '||text[i]=='\t'||text[i]=='\n'))
     {
           temp[j++]=text[i++];
     }
     temp[j]='\0';

       for(j=0;j<nocw;j++)
       {
          if(strcmp(temp,cenWords[j])==0)
          {
            strcat(finalText,"<censored> ");
            flag=1;
            break;
          }
       }
       
       if(flag==0)
       {
                  strcat(finalText,temp);
                  strcat(finalText," ");
       }
  }    
  
  printf("\n\n :: FINAL TEXT :: \n\n");
  puts(finalText);
 getchar();
 return 0;
}
 
0
Swapnil Chhajer
 
 
 
Question
main() 
{
float a=8.8;
double b=8.8;
if(a==b)
printf("Equal");
else
printf("not equal");
getch();
}
what is the output?
with reason
Rank Answer Posted By  
 Question Submitted By :: Subbu
I also faced this Question!!   © ALL Interview .com
Answer
here it will print :  either NOT EQUAL  or EQUAL
according to me and my compailer it's NOT EQUAL only.......
depends upon the compailer actually......

here variable 'a' is assigned wit float and 'b' is assigned
with double.... 
here comes the problem ie. of allocation of no. of bytes

according to my compailer float allocates 4 bytes and double
allocates 8 bytes.... so when it compares each location bit
by bit the float will lag by two bytes of space than double
has .. so since the comparsion takes a decision tat it's not
equal since it dosent check the other two locations of
double wit float which is lagging wit that two bytes of
memory space....... so it prints NOT EQUAL


thank you
 
0
Vignesh1988i
 
 
Answer
answer is not equal;
bcoz float cannot be compared with double.
 
0
Vikram
 
 
Answer
It will print "not equal". Reason is the difference in 
precision of the numbers. ie numbers like 8.8 or 8.1 can't 
be stored with complete precision in binary sysetm since 
it's mantissa part will not end but continues with a 
series. So value calculated for single precision(float) 
number will be slightly different from the value calculated 
for double precision (double) number. To verify this use 
gcc and gdb in linux.

If you try with numbers 8.25, 8.5 or 8.75 the program will 
print "equal" since the mantissa part ends with in the 
precision.

I think this has nothing to do with compiler version or 
inabilty of comparision.
 
0
Rakesh
 
 
Question
what is the advantage of using SEMAPHORES to ORDINARY
VARIABLES???
Rank Answer Posted By  
 Question Submitted By :: Jidhu
This Interview Question Asked @   NSN , Nsn
I also faced this Question!!   © ALL Interview .com
Answer
semaphores helps is a varible which is used to protect the shared data .hence avoiding the coruption of data by the threads acting simultaniously..
 
0
Test
 
 
Question
Write a C program that computes the value ex by using the 
formula
ex =1+x/1!+x2/2!+x3+3!+………….
Rank Answer Posted By  
 Question Submitted By :: Umayal
I also faced this Question!!   © ALL Interview .com
Answer
#include<stdio.h>
int main()
{
 char c = 'X';
 int i,n,sum = 0;
 printf("Enter values for n\n");
 scanf("%d\n",&n);
 for(i=0;i<n;i++)
 {
  sum = sum+power(c,i)/fact(i);
 }
 fact(int i)
 {
   int p=1 ,fact; 
   if(p<=i)
    {
     fact = p*fact(p++);
    } 
   return fact;
 }
 
0
Dally
 
 
Question
why r u join this company? give solid resons.
Rank Answer Posted By  
 Question Submitted By :: Sunnyl Rastogi
This Interview Question Asked @   Infosys , Ibm
I also faced this Question!!   © ALL Interview .com
Answer
bcoz i didn't get any other software company.
 
0
Krijesh
 
 
Answer
i want iearn everthing about softwares.
 
0
Gireesh
 
 
Answer
i want to be a part of it.As it is my pleasure.
 
0
Pushpendra
 
 
Answer
tell related to R&D of the company, new learning , the 
culture,the policy.
 
0
S
 
 
Answer
bcoz i wanna learn somethig i course of my service with 
self satisfaction and this company is tthe best to give me 
that opertunity
 
0
Kaberi
 
 
Answer
To pursue a dynamic and challenging career with your 
esteemed organization of , it will give me value addition 
to my career  as well as will also offer opportunity to 
enhance my professional skills.
 
0
Harrie007
 
 
Answer
it's the one and one leading company.team quatination is very super and excellent.the team leader is help to the staff.
encorage the team members.
 
0
Senthilkumar
 
 
Question
What is the difference between null pointer and void pointer
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   CTS , In MAQ Software
I also faced this Question!!   © ALL Interview .com
Answer
Null pointers returns null value and void pointer returns no
value
 
1
Gokul Saravanan
 
 
Answer
NULL POINTER :
the pointer which dosent point to any memory location is 
called NULL POINTER.

VOID POINTER :
the pointer is a one which can only point to a particular 
memory location of it's own type.... but when the pointer 
is given void it can be mde to point any location of 
different type
 
0
Vignesh1988i
 
 
Answer
what is except handling in c sharp?
 
0
Junejo
 
 
Question
Write a Program to print this triangle:
*
**
*
****
*
******
*
********
*
**********
use two nested loops.
Rank Answer Posted By  
 Question Submitted By :: Umayal
This Interview Question Asked @   TCS
I also faced this Question!!   © ALL Interview .com
Answer
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf("enter the lines :");
scanf("%d",&n);
for(int i=1;i<=n/2;i++)
{
printf("*\n");
for(int j=1;j<=2*i;j++)
printf("%d",j);
printf("\n");
}
if(n%2!=0)
printf("\n*");
getch();
}

thank u
 
0
Vignesh1988i
 
 
Answer
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf("enter the lines :");
scanf("%d",&n);
for(int i=1;i<=n/2;i++)
{
printf("*\n");
for(int j=1;j<=2*i;j++)
printf("*");
printf("\n");
}
if(n%2!=0)
printf("\n*");
getch();
}
 
0
Vignesh1988i
 
 
Answer
void main() {
   int n = 5 ; // take use input here
   int i, j;
   for( i =1; i<=n; i++){
     printf("\n *");
     for(j=0; j<=i; j++){
        printf(" *");
     }
   }
}
 
0
Naman Patidar
 
 
Answer
#include<stdio.h>
int main()
{
int n,i,j;
printf("enter the lines :");
scanf("%d",&n);
for(i=1;i<=n/2;i++)
{
printf("*\n");
for(j=1;j<=2*i;j++)
printf("*");
printf("\n");
}
if(n%2!=0)
printf("\n*");

}

compiled with GCC
 
0
Rfk
 
 
Answer
#include<stdio.h>
#include<conio.h>
main()
{
  int i,j;
  clrscr();
  for(i=1;i<=10;i++)
  {
     if(i%2!=0)
     printf("*\n");
     else
     {
      for(j=1;j<=i;j++)
      printf("*");
      printf("\n");
      }
    }
    getch();
}
 
0
Srinivas 9491582281
 
 
Answer
void main() {
   int n = 5 ; // take use input here
   int i, j;
   for( i =1; i<=n; i++){
     printf("\n *");
     for(j=1; j<i; j++){
        printf(" *");
     }
   }
}
 
0
Manoj
 
 
Question
who will call your main function in c under linux?
Rank Answer Posted By  
 Question Submitted By :: Raghu Kiran
I also faced this Question!!   © ALL Interview .com
Answer
_start will call the main function in c under linux
 
0
Valli
 
 
Answer
When the programme is commpiled,in the kernel execl will be
called (execl will replace current process image with new
process image)in the new process strat up routine
ia executed this start up routine is written in C abd assembly.
In this routine exit(main()); function will called,this will
call to main() function.

Kiransing Paradeshi
Software Engineer
SPA Comuters (P) Ltd
Banglore,India
kiransing4u@gmail.com
 
0
Kiransing Paradeshi
 
 
Question
write an interactive program to generate the divisors of a
given integer.
Rank Answer Posted By  
 Question Submitted By :: Tulika Srivastava
This Interview Question Asked @   TCS
I also faced this Question!!   © ALL Interview .com
Answer
#include <stdio.h>

void div(int n){
int i=2;
    while(n%i!=0 && i!=n){
         i++; 
    }
     printf("%d ",i);
	if(i!=n){
	  div(n/i);
	}

}

main(){
int i;
printf("Enter number:");scanf("%d",&i);
printf("1 ");
div(i);
}
 
0
Neo
 
 
Answer
void div(int n){
static int i=1;
    while(i<=n){
    if(!(n%i))printf(" %d",i);
         i++;
    }
}

main(){
int i;
clrscr();
printf("Enter number:");scanf("%d",&i);
div(i);
getch();
}
 
0
Tamil
 
 
Answer
#include<stdio.h>
int main()
{
 int n,i=1;
 printf("Value for n\n");
 scanf("%d\n",&n);
 while(i<=n)
 {
   if(n%i == 0)
   printf("%d\n",i);
  
   i++;
 }
}
 
0
Dally
 
 
Answer
same program as above, optimising it a little bit.

#include<stdio.h>
int main()
{
 int n,i=1;
 printf("Value for n\n");
 scanf("%d\n",&n);
 while(i <= n/2)
 {
   if(n%i == 0)
   printf("%d\n",i);
  
   i++;
 }
 printf("%d\n",n);
}
 
0
Pradeep
 
 
Question
what is the advantage of software development
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
To decrease the complexcity of the user problem and fast 
work
 
0
Shubham Singh
 
 
Question
how to return 1000 variables from functio9n in c?plz give me
code also
Rank Answer Posted By  
 Question Submitted By :: Prasad237
I also faced this Question!!   © ALL Interview .com
Answer
SEE /...  we cant return 1000 variables at a time ... using
call by value......  only call by reference can do it....
tat is. usage of pointers...... since it will change
directly in the address itself.... that's a specality...


#include<stdio.h>
#include<conio.h>
void fun(int *,int *,int *.............1000 int's );
void main()
{
int a1,b1,c1,d1,.............a1000;
fun(&a1,&a2,...... &a1000);
for(int i=0;i<1000;i++)
printf("\n %d",a1);
getch();
}
void fun(int *a1,int *b2,.......... 1000 ptr declarations)
{
*a1=1;
*a2=2
.
.
.
.
.
.
100th varaible =1000;
}
 
0
Vignesh1988i
 
 
Answer
extending the previous answer by passing array instead of
all variables
 
0
Codee
[Not Yet Placed]
 
 
Answer
you r right sir.... but he has asked 1000 VARIABLES.. so
only i done in this way.....
 
0
Vignesh1988i
[Not Yet Placed]
 
 
Answer
the first answer is quite long......

just pass an array(1000 elements) and return that.....
 
0
Mishra@deepa
[Not Yet Placed]
 
 
Answer
#include<stdio.h>
int fun(int *a)
{
    return ++(*a);
}
     
int main()
{
    int a=0,i,d;
      for(i=0;i<100;i++)
      {
                       d=fun(&a);
                       printf("\n%d",d);
      }
    getch();
}
 
0
Ramachandran
[Not Yet Placed]
 
 
Question
What is the difference between big endian form and little 
endian form? write a code to convert big endian form to 
little endian and vice versa..
Rank Answer Posted By  
 Question Submitted By :: Lakshmi
This Interview Question Asked @   Aricent
I also faced this Question!!   © ALL Interview .com
Answer
Little endian has least significant digit at far left.
Big endian has most significant digit at far left.
 
0
Peter
 
 
Answer
the endianness of a bus determines whether the MSB is put
into the lowest address
(big-endian) or in the highest address (little-endian).
 
0
Amit
 
 
Answer
Little Endian ->LSB at lower address
Big Endian -> MSB at lower address
e.g:
    if the value is 0x0A0B0C0D then
in case of LE storage will be
Address 1000 0D
Address 1001 0C
Address 1002 0B
Address 1003 0A

in case of BE storage will be
Address 1000 0A
Address 1001 0B
Address 1002 0C
Address 1003 0D

Marco to convert(this will convert from LE to BE or BE to 
LE--> one for all :) )

#define CON(NUM) (NUM&0x000000FF)<<24|(NUM&0x0000FF00)<<8 
|NUM&0x00FF0000)>>8 |(NUM&0xFF000000)>>24
 
0
Raj
 
 
Answer
Small correction in above macro.
'(' was missing in second line.

#define CON(NUM) (NUM&0x000000FF)<<24|(NUM&0x0000FF00)<<8 
|(NUM&0x00FF0000)>>8 |(NUM&0xFF000000)>>24
 
0
Vish
 
 
Question
Design a program using an array that searches a number if it
is found on the list of the given input numbers and locate
its exact location in the list.
Rank Answer Posted By  
 Question Submitted By :: Enzo
I also faced this Question!!   © ALL Interview .com
Answer
here i have used a concpt of pointers .. ie. array of
pointers....  when you search for a number it may occur once
 or more than it... i have designed for all cases.. that's
why i used pointers......................

#include<stdio.h>
#include<conio.h>
void main()
{
int ch[100],m,n,*ptr[20],count=0;
printf("enter the limit value");
scanf("%d",&m);
for(int i=0;i<m;i++)
scanf("%d",&a[i]);
printf("enter the number u are searching for :");
scanf("%d",&n);
for(i=0,k=0;i<m;i++)
{
if(a[i]==m)
{
count++;
ptr[k]=&a[i];
k++;
}
for(i=0;i<count;i++)
printf("the number occured %d times and found to be int
these addresses : %u ",count,*(*(ptr+i)));
getch();
}
 
0
Vignesh1988i
 
 
Answer
small mistake in above program.... in last printf pl. change
     
*(*(ptr+i)) as  (*(ptr+i))
 
0
Vignesh1988i
 
 
Answer
dear no need of pointer for the above Question dear 

#include<stdio.h>
#include<conio.h>
void main()
{
int ch[100],m,n,flag=0;
printf("enter the limit value");
scanf("%d",&m);
for(int i=0;i<m;i++)
scanf("%d",&a[i]);
printf("enter the number u are searching for :");
scanf("%d",&n);
for(i=0;i<m;i++)
{
if(a[i]==n)
{  
     printf("%d number is found at the position %d in the
given array ",n,i);
     i=m;// to come out from the loop when we found
searching number
     flag=1;

}
}


if( flag = 0)
{ 
printf(" given number is not found in the list of array");

}




getch();
}
 
0
Ashwin Kumar
 
 
 
Back to Questions Page
 
 
 
 
 
   
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