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                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories >> Software >> Programming-Languages >> C
 
 


 

Back to Questions Page
 
Question
i want explaination about the program and its stack reprasetaion

fibbo(int n)
{
if(n==1 or n==0)
return n;
else
return fibbo(n-1)+fibbo(n-2);
}
main()
{
fibbo(6);
}
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
here the return function will give an error message or it 
will only take the first function (ie) fibbo(n-1) since 
after return this is the first recursive function 
called.... so this altast return 1 to the main program.... 
that's all.... as for as i know this will be the 
procedure...... and then the "or" must not be used .. only 
logicalOR must be used ||.........
 
0
Vignesh1988i
 
 
Answer
#include <stdio.h>

int fibonacci ( int nNumber )
{
	if ( ( nNumber == 0 ) || ( nNumber == 1 ) ) return 
( nNumber );
	return  fibonacci ( nNumber -1 )  + fibonacci ( 
nNumber - 2 ) ;
}


int main ( int argc, char* argv[] )
{
	printf ( "\n The Fibnoci value :%d", fibonacci ( 
5 ) );
	return ( 1 );


Other than the logical or, everyting is perfect, the 
function will recursivel bubble down and for this value it 
ud become like this if u copy this to a notepad, with 
formating, it ud be easy to understand

				4 		+ 	
				3

		3		+		2	
		2		+		1

	2	+	1		1	+	0
	1	+	0		( will return 1 )

1 	+	0 ( all others will return 1 )
 
0
Abdur Rab
 
 
Question
How to receive strings with spaces in scanf()
Rank Answer Posted By  
 Question Submitted By :: Niharika_dash
I also faced this Question!!   © ALL Interview .com
Answer
using the function 
gets(variable)
 
0
Karthik
 
 
 
Answer
#include<stdio.h>
#include<conio.h>
void main()
{
char a[50];
printf("enter the string :");
for(int i=0;1;i++)
{
scanf("%c",&a[i]);
if(a[i]=='\n')
a[i]='\0'
break;
}
for(i=0;a[i]!='\0;i++)
printf("%c",a[i]);
getch();
}
 
0
Vignesh1988i
 
 
Answer
#include<stdio.h>
#include<conio.h>
void main()
{
char a[50];
printf("enter the string:");
scanf("%s",&a);
printf("%s",a);
getch();
}
 
0
Parmjeet Kumar
 
 
Answer
char a[50];
use scanf(" %[^\n]",a);
 
0
Valli
 
 
Question
Write a program in c to input a 5 digit number and print it
in words.
Rank Answer Posted By  
 Question Submitted By :: Niharika_dash
I also faced this Question!!   © ALL Interview .com
Answer
#include<stdioi.h>
void main()
{
int n,count=0,a[20];
scanf("%d",&n);
for(i=0;n>0;i++)
{
a[i]=n%10;
n=n/10;
count++;
}
for(i=0;i<count;i++)
{
switch(a[i])
{
case 1:
printf("one");
break;
case 2:
printf("two");
break;
  like this print upto case 0 , (ie) after case 9 ... put
case 0.... and finish the switch and close the loop.......
 
3
Vignesh1988i
 
 
Question
a C prog to swap 2 no.s without using variables just an 
array?
Rank Answer Posted By  
 Question Submitted By :: Ninad
This Interview Question Asked @   TCS
I also faced this Question!!   © ALL Interview .com
Answer
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("Enter the number:");
scanf("%d%d",&a,&b)
a=a+b;
b=a-b;
a=a-b;
printf("%d%d",a,b);
getch();

}
 
0
Sankar Kiran
 
 
Answer
void main()
{
int a=10,b=20;
a^=b^=a^=b;
printf("a=%d,b=%d",a,b)
getch();
}
 
0
Karthik
 
 
Answer
void main()
{
int a[2]={20,10};
a[0]=a[0]^a[1];
a[1]=a[0]^a[1];
a[0]=a[0]^a[1];
printf("a=%d,b=%d",a[0],a[1])
getch();
}
 
0
Jaspreet Singh
 
 
Answer
void main()
{
int a,b;
printf("enter the two numbers\n");
scanf("%d%d",&a,&b);
printf("a=%d\n b=%d\n",a,b);
a=a+b-(b=a);
printf("a=%d\n b=%d\n",a,b);
getch();
}
 
0
Baidyanath Bisoyi
 
 
Question
Find string palindrome 10marks

Rank Answer Posted By  
 Question Submitted By :: Nazim
This Interview Question Asked @   Honeywell , Roland
I also faced this Question!!   © ALL Interview .com
Answer
void main()
{
 int a,len,palin;
 char s[20];
 
 scanf("%s",s);
 
 len=strlen(s);
 printf("%d \n",len);
 
 for(a=0,len=len-1;a<len;a++,len--)
 {
     if(s[a]==s[len])
         palin=1;
      
	  else 
           break;
 }

  if(palin==1)
     printf("string %s is palindrome",s);
 else
      printf("string %s is not palindrome",s);

getch();

}
 
0
Babitha
 
 
Answer
#include <stdio.h>

int isPalindrome ( char* str, int nLength )
{
	if ( nLength < 1 ) return ( 1 );
	if ( str [0] == str [ nLength -1 ] ) return ( 
isPalindrome ( ( str + 1 ) , ( nLength - 2 ) ) );
	else return ( 0 );
}

int main (int argc, char* argv[])
{
	char a[10] = {"ropepor"};
	if ( isPalindrome  ( a, strlen ( a ) ) ) printf 
("\n The string is Palindrome");
	else printf ("\n The string is NOT Palindrome");
	return (1 );
 
0
Abdur Rab
 
 
Answer
void main()
{
 int a,len,palin;
 char s[20];
 
 scanf("%s",s);
 
 len=strlen(s);
 printf("%d \n",len);
 
 for(a=0,len=len-1;a<len;a++,len--)
 {
    palin=0;
     if(s[a]==s[len])
         palin=1;
      
	  else
{ 
printf("string %s is not palindrome",s);
getch();
exit();
}
  }
printf("string %s is palindrome",s);    
getch();

}
 
0
Coolcom(chandan)
 
 
Answer
bool
IsPalindrome( char *lpStr )
{
	int n,i;
	n = strlen( lpStr );
	for ( i = 0; i < n/2; i++ )
	{
		if ( lpStr[i] != lpStr[n-i-1] )
		{
			return FALSE;
		}
	}
	return TRUE;
}
 
0
Vivek
 
 
Answer
#include"string.h"
void main()
{
char *str,*rev;
int i,j;
clrscr();
printf("\nEnter a string:");
scanf("%s",str);
for(i=strlen(str)-1,j=0;i>=0;i--,j++)
rev[j]=str[i];
rev[j]='\0';
if(strcmp(rev,str))
printf("\nThe string is not a palindrome");
else
printf("\nThe string is a palindrome");
getch();
}
 
0
Abhilash Meda
 
 
Question
what is out put of the following code? 
#include
class Base
{
Base()
{
cout<<"constructor base";
}
~Base()
{
cout<<"destructor base";
}
}
class Derived:public Base
{
Derived()
{
cout<<"constructor derived";
}
~Derived()
{
cout<<"destructor derived";
}
}
void main()
{
Base *var=new Derived();
delete var;
}

Rank Answer Posted By  
 Question Submitted By :: Nazim
This Interview Question Asked @   Honeywell
I also faced this Question!!   © ALL Interview .com
Answer
error.
because, there is no header file.
and no ";" is given after the end of classes.
 
0
Pooja Sonawane
 
 
Answer
there is no include file iostream for cout
immproper ending for classes ';'
 
0
Anvesh
 
 
Question
Write a C function to search a number in the given list of 
numbers. donot use printf and scanf
Rank Answer Posted By  
 Question Submitted By :: Nazim
This Interview Question Asked @   Honeywell
I also faced this Question!!   © ALL Interview .com
Answer
#include<stdio.h>
#include<conio.h>
void main()
{
char a[]="enter the no. of terms tou are going to enter :";
char a1[100];
char n;
puts(a);
int flag=0;
n=getchar();
int n1;
n1=(int)n    /* type casting*/
   for(int i=0;i<n1;i++)
      {
    a[i]=getchar();
}
char a3[]="enter the number do you want to find :";
puts(a3);
char s;
  s=getchar();
int b=(int)s;
  for(i=0;i<n1;i++)
{
     if(b==(int)a[i])
flag=1;
   }
if(flag==1)
printf("number is found");
else 
printf("not found");
getch();
}
this was the logic suddenly striked me.......................
 
0
Vignesh1988i
 
 
Answer
very sorry yaar/.... i forgettenly used printf statements in
my before posts.......... i think this can be the logic...
if am not wrong..............

#include<stdio.h>
#include<conio.h>
void main()
{
char a[]="enter the no. of terms tou are going to enter :";
char a1[100];
char n;
puts(a);
int flag=0;
n=getchar();
int n1;
n1=(int)n    /* type casting*/
   for(int i=0;i<n1;i++)
      {
    a[i]=getchar();
}
char a3[]="enter the number do you want to find :";
puts(a3);
char s;
  s=getchar();
int b=(int)s;
  for(i=0;i<n1;i++)
{
     if(b==(int)a[i])
flag=1;
   }
if(flag==1)
{
char q[]="number is found";
puts(q);
}
else
{
char w[]="number not found";
puts(w);
}
getch();
}
 
0
Vignesh1988i
 
 
Answer
Dear... Vignesh... r u tested?
if tested..., on what Compiler...
 
0
Gg
 
 
Answer
ya..... sorry... it wont work... since getchar gets only one
character the time.... when we give 48... i will take 4 and
8 .. but not as 48.... sorry for posting it... a lesson i
have learnt
 
0
Vignesh1988i
 
 
Answer
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main ( int argc, char* argv[] )
{
	int array [ 10 ] = { 546, 541, 128, 1027, 1000, 
10234, 657, 343, 111, 272 };
	char _variable [ 50 ];
	int _count = 0;
	int _value = 0;

	memset ( _variable, '\0', 50 );
	puts ("Enter the number to search: ");
	gets ( _variable );
	
	_value = atoi ( _variable );

	for ( _count = 0; _count < 10; _count++ ) {
		if ( array [ _count ] == _value ) {
			puts ("Search SUCCESSFUL");
			return ( 0 );
		}
	}
	puts ("Search NOT SUCCESSFUL");
	return ( 1 );
}

If u guys really want to check the given input is numeric, 
use isnumeric function defined in ctypes.h
 
0
Abdur Rab
 
 
Answer
sorry for the wrong information use isdigit(char)
 
0
Abdur
 
 
Question
If 4 digits number is input through the keyboard, Write a 
program to calculate sum of its 1st & 4th digit.
Rank Answer Posted By  
 Question Submitted By :: Ydw_10
I also faced this Question!!   © ALL Interview .com
Answer
#
#
void main()
{
int num,n1,n2,sum;
cout<<"enter a 4 digit no.";
cin>>num;
n1=num/1000;
n2=num%10;
sum=n1+n2;
cout<<"sum of 1st & 4th digit is"<<sum;
}
 
0
Bharghavi
 
 
Answer
#include<stdio.h>
main()
{
int n,n1,n4;
printf("Enter 4 digit number:");
scanf("%d",&n);
n4=n%10;
n1=n/100;
printf("\nResult=",(n1+n4));
getch();
}

 
0
Anvesh
 
 
Answer
thiz z how 2 find the sum of first and last digit of any 
number

#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
long int n,nf,nl,temp;
int count=-1;
printf("Enter a number:");
scanf("%ld",&n);
temp =n;
while(temp<0)
{
  temp=temp/10;
c++;
}
nl=n%10;
nf=n/(pow(10,c));
printf("\n%ldResult=",(nf+nl));
getch();
}
 
0
Kadher Masthan ,...sit
 
 
Answer
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int num,n1,n2,sum;
clrscr();
printf("Enter 4 digit number:");
scanf("%d",&num);
n1=num/1000;
n2=num%10;
sum=n1+n2;
printf("Sum of 1st & 4th digit number is=%d",sum);
getch();
}
enjoy!!!!!!!!!!!!

any program just mail me:
ssmartinp@gmail.com
 
0
Sourav Sinha
 
 
Question
what is the code for getting the output as 
                     *
                     **
                     ***
Rank Answer Posted By  
 Question Submitted By :: Madhavan
This Interview Question Asked @   Caritor , Caritor
I also faced this Question!!   © ALL Interview .com
Answer
main()
{
printf("*\n**\n***);
}
OR
main()
{
int n,i;
while(n<3)
{
i=0;
while(i<=n)
{printf("*");i++;}
printf("\n); n++;
}
 
0
Anvesh
 
 
Answer
void main()
{
int i,j;
for(i=0;i<3;i++)
printf("\n");
for(j=0;j<i;j++)
printf("*");
}
 
1
Pooja Sonawane
 
 
Answer
# include <Stdio.h>
# include <conio.h>
# include <string.h>

void main()
{
	int j,i,n;

	scanf("%d",&n);

	for (i=0;i<=n;i++)
	{
		for(j=0;j<i;j++)
			printf("*");
		printf("\n");
    }

	getch();

}
 
0
Babitha
 
 
Answer
#include<stdio.h>
main()
{
int n,i=0,j=0;
printf("Enter an intger : ");//upto n nof *'s
scanf("%d",&n);
while(j<n)
        {
        for(i=0;i<=j;printf("*"),i++);
        printf("\n",j++);
        }
}
 
0
Gg
 
 
Answer
void main()
{
int i,j;
for(i=0;i<3;i++){
  for(j=0;j<i;j++){
    printf("*");
    printf("\n");
  }
}
}
 
0
Sourisengupta
 
 
Question
You are given a string which contains some special
characters. You also have set of special characters. You are
given other string (call it as pattern string). Your job is
to write a program to replace each special characters in
given string by pattern string. You are not allowed to
create new resulting string. You need to allocate some new
memory to given existing string but constraint is you can
only allocate memory one time. Allocate memory exactly what
you need not more not less.
Rank Answer Posted By  
 Question Submitted By :: Rajendra_ait
This Interview Question Asked @   Microsoft , Dfqs
I also faced this Question!!   © ALL Interview .com
Answer
#include <stdio.h>
#include <string.h>

/**
 * int copy ( char* str, char* _pattern_to_copy, int 
number_of_bytes_moved, int total_size_allocated, int 
diff_size )
 * @param str, the pointer from where the pattern starts
 * @param _pattern_to_copy, what needs to be placed insted 
of the pattern
 * @param number_of_bytes_moved, the number of bytes at 
which the pattern first appeared
 * @param total_size_allocated, the total size the space 
has been allocated (eliminating the space for NULL)
 * @param diff_size, the difference between the pattern and 
the string that needs to be replaced
 *
 */
int copy ( char* str, char* _pattern_to_replace, int 
number_of_bytes_moved, int total_size_allocated, int 
diff_size )
{
	int _loop = 0;

	/**
	 * Starting from end, move towards untill the 
pattern appears
	 * start point is array start + the 
number_of_bytes_moved (first apperance of the pattern)
	 * so the end point should be array end - 
number_of_bytes_moved (the last space before the NULL 
character
	 * move the array down to create space for the 
string to be replaced 
	 */
	for ( _loop = total_size_allocated; ( 
total_size_allocated - number_of_bytes_moved ) >  
diff_size; total_size_allocated-- )
	{
		str [ total_size_allocated - 
number_of_bytes_moved ] = str [ total_size_allocated - 
number_of_bytes_moved - diff_size ];
	}

	/**
	 * Replace the string on the pattern
	 * Use memcpy since it does not copy provide NULL 
by itself
	 */
	memcpy ( str, _pattern_to_replace, strlen ( 
_pattern_to_replace ) );

	return ( 0 );
}

int main ( int argc, char* argv [] )
{
	char* string_value = NULL;
	char pattern_to_replace [] = {"replacement"};
	char pattern_2b_replaced [] = {"#"};
	int _count = 0;
	char* _ptr = NULL;
	int alocation_size = 0;
	int number_of_bytes_moved = 0;
	int old_strlen = 0;

	/**
	 * Allocate the size to hold the orignal string
	 * copy the required string with the pattern
	 */
	string_value = ( char* ) malloc ( 26 * sizeof ( 
char ) );
	if ( NULL != string_value ) 
	{
		strcpy ( string_value, "Hi # of new # 
string by #" );
	}

	/**
	 * Count the number of occurences of the pattern.
	 */
	_ptr = string_value;
	while ( _ptr = strstr ( _ptr, 
pattern_2b_replaced ) )
	{
		_ptr += 1;
		_count++;
	}

	/**
	 * Calculate the size of the new string that needs 
to be accomadated
	 * the number of times the pattern occurs in the 
original string
	 */
	alocation_size = ( strlen ( pattern_to_replace ) - 
strlen ( pattern_2b_replaced ) ) * _count; // calculated 
size of new string
	alocation_size += strlen ( string_value ); 	
			          // add the size of old 
string
	old_strlen = strlen ( string_value ) + 1;	
				  // allocate space to 
store NULL

	/**
	 * Increase the space in the old pointer using 
realloc
	 * and copy '&' in the newly allocated spaces alone
	 * just for the sake of our reference.
	 *
	 * Remember to exclude the 1 which we allocated for 
the NULL character
	 */
	string_value = ( char* ) realloc ( string_value, ( 
alocation_size * sizeof ( char ) ) );
	memset ( ( string_value + old_strlen) , '&', ( 
alocation_size - old_strlen - 1 ) );

	/**
	 * Store the NULL at the end of the total allocated 
size
	 * we use alocation_size - 1
	 * 
	 * eg: a[5] means 6th location in the array
	 * If we want to store at the 6th location 
	 * we need to provide 5 (ie. alocation_size - 1)
	 */
	string_value [ alocation_size - 1 ] = '\0';

	/**
	 * Replace the string needs to be filled
	 */
	_ptr = string_value;
	while ( _ptr = strstr ( _ptr, 
pattern_2b_replaced ) )
	{
		number_of_bytes_moved = ( _ptr - 
string_value );
		copy ( _ptr, pattern_to_replace, 
number_of_bytes_moved, ( alocation_size - 1 ), 
				( strlen ( 
pattern_to_replace ) - strlen ( pattern_2b_replaced ) ) );
		_ptr += 1;
	}


	printf ( "\n string :%s, no of occurence :%d, 
size :%d", string_value, _count, alocation_size );

	free ( string_value );
}
 
0
Abdur Rab
 
 
Answer
no this answer is not correct
 
0
Raja
 
 
Question
what is the output of below pgm?
void main()
{
 int i=0;
if(i)
printf("pass");
else
printf("fail");
}
Rank Answer Posted By  
 Question Submitted By :: Raji
I also faced this Question!!   © ALL Interview .com
Answer
fail
because here if is taking 0 boolean value means condition
becomes false and else will be executed
 
5
Himanshu Goel
 
 
Answer
fail
 
5
Sweta
 
 
Answer
FAIL



THANK U
 
0
Vignesh1988i
 
 
Question
Is the C language is the portable language...If yes...Then 
Why...and if not then what is problem so it is not a 
Portable language..???
Rank Answer Posted By  
 Question Submitted By :: Chitransh
This Interview Question Asked @   TCS
I also faced this Question!!   © ALL Interview .com
Answer
C as a language is portable across any platforms, as it 
needs a compiler to compile in different platforms.

The drawback of compiled 'C' code is "Architecture 
Dependent" and hence the code compiled in 32 bit 
architecture cannot be used for 64 bit.
 
0
Abdur Rab
 
 
Question
without a  terminator how can we print a message in a printf
() function.
Rank Answer Posted By  
 Question Submitted By :: Pradeep
This Interview Question Asked @   NIIT
I also faced this Question!!   © ALL Interview .com
Answer
#include<stdio.h>
main()
{
   if(Printf("Here is the message without terminator"))
   {
   }
}
 
0
Vijay
 
 
Answer
we can make without using if,for,while statments.....

main()
{
  fun(printf("\nCute Ramya !!!!!"));
}
fun(int i)
{
;;;;; i++
}
 
0
Dharmendra
 
 
Answer
#include<stdio.h>

void main()
{
  fun(printf("\nCute Ramya !!!!!"));
}
fun(int i)
{
i++;
}
 
0
Indrani
 
 
Answer
#include<stdio.h>
#include<conio.h>
main()
{
      if("adesh")
       {
        }
}
 
0
Adesh
 
 
Answer
#include<stdio.h>
main()
{
 if(printf("the message is print without terminator"))
}
 
0
Dewanshu Goel
 
 
Question
Give me basis knowledge of c , c++...
Rank Answer Posted By  
 Question Submitted By :: Gopal_dp_shah
I also faced this Question!!   © ALL Interview .com
Answer
c is a procedural language and C++ is object oriented 
language
 
2
Nirmal Kumar Tailor
 
 
Answer
c uses the top-down approach.c++ uses bottom-up approach
 
3
Raji
[ESSAR STEEL Ltd.]
 
 
Answer
c having no security for data..but c++ having that 
security,using class(access specifier).
 
5
Raji
[ESSAR STEEL Ltd.]
 
 
Answer
in C structures are used...but in cpp classes are 
used..which is more secured
 
0
Sri
[ESSAR STEEL Ltd.]
 
 
 
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