GeekInterview.com
Series: Subject: Topic:

C Interview Questions

Showing Questions 1 - 20 of 827 Questions
First | Prev | | Next | Last Page
Sort by: 
 | 

Two numbers are entered through keyboard, write a program to find the value of one number raised to the power another.

Asked By: sweety | Asked On: Oct 28th, 2007

Answered by: shweta gupta on: Jul 21st, 2014

It traverse the char type format specifier from left to right and assign the value from stdin to the address of the variable. Scanf return type is int and return the number of argument.


Its syantax is scanf(const char *,...), there is the ... represent the variable argument list.

Answered by: sudhakar on: Jul 19th, 2014

How to work the scanf function?

The C language terminator isa. Semicolonb. Colonc. Periodd. Exclamation mark

Asked By: Interview Candidate | Asked On: Jun 7th, 2005

Answered by: priyanka on: Jul 7th, 2014

B.colon

Answered by: rubini kandasamy on: Mar 6th, 2014

A.semicolon

What change is required in the following program so that its output becomes 3,6,11,20,37,......1034?

Asked By: Swati Goel | Asked On: Dec 1st, 2012

Code
  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5. int a=1,r=2,i;
  6. for (i=0;i<=10;i++)
  7. printf(",%d ", a * pow(r,i));
  8. return 0;
  9. }

Answered by: nira on: Jul 1st, 2014

Much easier approach, this is a logic question, not programming

Code
  1.    
  2.     #include<stdio.h>
  3.     #include<math.h>
  4.     int main()
  5.     {
  6.     int a=1,r=2,i;
  7.     for (i=0;i<=10;i++)
  8.     printf(",%d ", a * pow(r,i) + i);
  9.     return 0;
  10.     }

Answered by: shweta gupta on: Jun 25th, 2014

Code
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int temp=3;
  6. for(int i=0;i<10;i++){
  7.         cout<<temp<<endl;
  8.         temp=temp*2-i;
  9.  
  10.  
  11. }
  12.  
  13.     return 0;
  14. }

Write a program to convert numbers into words?For ex: 547five hundred and forty seven

Asked By: Preetham | Asked On: Oct 4th, 2006

Answered by: Shridhar on: Jun 27th, 2014

Code
  1. #include<stdio.h>
  2. main() {        int n,u,t,h,th;            
  3. jamkhandi: printf("enter a 4 digit non negative number  ");    
  4. scanf("%d",&n);    
  5.  if(n<0) goto jamkhandi;    
  6.   printf(" the entered number is :-  ");    
  7.  if(n==0)printf("zero ");    
  8. else {          
  9. u=n%10;        
  10. n=n-u;    
  11.         t=n%100; t=t/10;        
  12. h=n%1000;
  13. h=h/100;        
  14. th=n%10000; th=th/1000;         }        
  15. switch(th)    {         case 1: {                    
  16. char th1[100]="one thousand";                        
  17. printf("%s ",th1);break;             }            
  18.  case 2: {                 
  19. char th1[100]="two thousand";                        
  20. printf("%s ",th1);break;             }            
  21. case 3: {                    
  22. char th1[100]="three thousand";                      
  23. printf("%s ",th1);break;             }            
  24. case 4: {                    
  25. char th1[100]="four thousand";                       
  26. printf("%s ",th1);break;             }                          
  27. case 5: {                  
  28.  char th1[100]="five thousand";                      
  29. printf("%s ",th1);break;             }            
  30. case 6: {                    
  31. char th1[100]="six thousand";                        
  32. printf("%s ",th1);break;             }            
  33. case 7: {                  
  34.  char th1[100]="seven thousand";                   
  35.  printf("%s ",th1);break;             }            
  36. case 8: {                  
  37.  char th1[100]="eight thousand";                     
  38. printf("%s ",th1);break;             }            
  39. case 9: {                    
  40. char th1[100]="nine thousand";                       
  41. printf("%s ",th1);break;             }    }  
  42. switch(h)    {          case 1: {                    
  43. char h1[100]="one hundred";                  
  44. printf("%s ",h1);break;             }            
  45. case 2: {                    
  46. char h1[100]="two hundred";                  
  47. printf("%s ",h1);break;             }            
  48. case 3: {                    
  49. char h1[100]="three hundred";                        
  50. printf("%s ",h1);break;             }            
  51. case 4: {                  
  52.  char h1[100]="four hundred";                        
  53. printf("%s ",h1);break;             }                        
  54.  case 5: {                   
  55. char h1[100]="five hundred";                         
  56. printf("%s ",h1);break;             }            
  57.  case 6: {                 
  58.  char h1[100]="six hundred";                       
  59.  printf("%s ",h1);break;             }          
  60.   case 7: {                  char h1[100]="seven hundred";                 
  61.  printf("%s ",h1);break;             }          
  62.   case 8: {                  char h1[100]="eight hundred";               
  63.    printf("%s ",h1);break;             }          
  64.   case 9: {                  char h1[100]="nine hundred";                
  65.   printf("%s ",h1);break;             }    }    
  66.   switch(t)     {          case 1:             
  67.  { if(u==1)              {                     
  68. char t1[100]={e,l,e,v,e,n,};
  69.         printf("%s",t1);        
  70. break;         }
  71.          if(u==2)                {                     
  72. char t1[100]={t,w,e,l,v,e,};        
  73.  printf("%s",t1);       break;         }  
  74.        if(u==3)                  {                     
  75. char t1[100]={t,h,i,r,t,e,e,n,};      
  76.   printf("%s",t1);      
  77. break;    
  78.     }         if(u==4)         
  79.  {                     
  80. char t1[100]={f,o,u,r,t,e,e,n,};    
  81.     printf("%s",t1);            
  82. break;         }      
  83.    if(u==5)              {                     
  84. char t1[100]={f,i,f,t,e,e,n,};      
  85.   printf("%s",t1);      
  86. break;      
  87.    }      
  88.   if(u==6)             
  89.  {                     
  90. char t1[100]={s,i,x,t,e,e,n,};  
  91.       printf("%s",t1);          
  92. break;         }    
  93.      if(u==7)            {                     
  94. char t1[100]={s,e,v,e,n,t,e,e,n,};        
  95.  printf("%s",t1);       break;         }    
  96.      if(u==8)            {                     
  97. char t1[100]={e,i,g,h,t,e,e,n,};        
  98.  printf("%s",t1);       break;         }      
  99.   if(u==9)               {                     
  100. char t1[100]={n,i,n,t,e,e,n,};        
  101.  printf("%s",t1);    
  102.         break;         }         if(u==0)      
  103.   {        
  104.         char t1[100]={t,e,n,};          
  105. puts(t1);        
  106.         break;      }            }             
  107.  case 2: {                     
  108. char t1[100]={t,w,e,n,t,y,};    
  109.                 printf("%s ",t1);                      
  110. break;           }               
  111.  case 3: {               
  112.         char t1[100]={t,h,i,r,t,y,};           
  113.  printf("%s ",t1);                             
  114. break;           }                               
  115.  case 4: {               
  116.         char t1[100]={f,o,r,t,y,};                     
  117. printf("%s ",t1);                
  118.         break;           }               
  119.  case 5: {             
  120.         char t1[100]={f,i,f,t,y,};                     
  121. printf("%s ",t1);                      
  122. break;         
  123.  }               
  124.  case 6: {                     
  125. char t1[100]={s,i,x,t,y,};                     
  126. printf("%s ",t1);                      
  127. break;           }               
  128.  case 7: {                     
  129. char t1[100]={s,e,v,e,n,t,y,};                 
  130. printf("%s ",t1);                      
  131. break;           }               
  132.  
  133. case 8: {                      
  134. char t1[100]={e,i,g,h,t,y,};                   
  135. printf("%s ",t1);                      
  136. break;           }               
  137.  
  138. case 9: {                      
  139. char t1[100]={n,i,n,e,t,y,};                   
  140. printf("%s ",t1);                                              
  141. break;           }                 }  
  142.  if(t!=1)    {         
  143. switch(u)    {         
  144.  case  1: {            
  145.   char u1[100]={o,n,e,};               
  146.  puts(u1);               
  147. break;                   }  
  148.          case 2:  {      
  149.  char u1[100]={t,w,o,};                
  150.  puts(u1);             
  151.  break;                  }                             
  152. case 3:
  153.  {         char u1[100]={t,h,r,e,e,};    
  154.        puts(u1);               
  155.   break;                 }                    
  156.    case 4:  {    
  157.  char u1[100]={f,o,u,r,};              
  158.  puts(u1);             
  159.   break;             
  160.     }                    case 5:  {      
  161.  char u1[100]={f,i,v,e,};              
  162.  puts(u1);         
  163.      break;              }               
  164. case 6:  {         char u1[100]={s,i,x,};              
  165.  puts(u1);               
  166. break;                   }             
  167.  case 7:  {        
  168. char u1[100]={s,e,v,e,n,};             
  169.  puts(u1);           
  170.     break;               }             
  171.  case 8:  {      
  172.  char u1[100]={e,i,g,h,t,};            
  173.   puts(u1);            
  174.  break;                  }           
  175.     case 9:  {    
  176.  char u1[100]={n,i,n,e,};      
  177.          puts(u1);               
  178. break;                   }       }    }        
  179. getch(); }
  180.  </stdio.h>

Answered by: Chahit on: Jun 12th, 2014

The correct code is following (it works for till user enters max value for int i.e. 2,147,483,647)"java /* * Program to convert entered number into string * */ package com.orkas...

Print number of distinct characters in a string.

Asked By: levis | Asked On: Nov 23rd, 2011

How do I implement a C program that reads a string and prints a table with the number of occurrences of each character in the string. ex: rubber. R = 2, u = 1, b = 2, e = 1.

Answered by: shweta gupta on: Jun 25th, 2014

Code
  1.  
  2. int main()
  3.  
  4. {
  5.  
  6. char str[11]="aabcadefge";
  7. int a[26];
  8. for(int i=0;i<26;i++) a[i]=0;
  9. int couner=0;
  10. for(int i=0;str[i]!=;i++){
  11.         a[(str[i]-a)]+=1;
  12. }
  13.  
  14.  

Answered by: jbode on: Aug 31st, 2012

Simple, fairly brain-dead example. Assumes any input characters fall into the range [0...CHAR_MAX). "c #include #include #include int main(int argc, char **argv) { int coun...

C program to count numbers of positive and negative numbers

Asked By: Tai | Asked On: Oct 12th, 2007

Write a C program using arrays to count the numbers of positive and negative numbers which accepts the inputs as "size of the array" & "elements of the array" and outputs as "number of negative numbers in an array are" & "numbers of positive numbers in an array are" ?

Answered by: shweta gupta on: Jun 25th, 2014

Code
  1. #include<iostream>
  2. #include<stdio.h>
  3. using namespace std;
  4. int main(){
  5. cout<<"enter the size of array"<<endl;
  6. int size,count_neg=0,count_pos=0;
  7. cin>>size;
  8. int a[size];
  9. for(int i=0;i<size;i++){
  10. cout<<"enter element of a["<<i<<"]=";
  11. cin>>a[i];
  12. if((a[i]>>31)==-1) count_neg++;
  13. else count_pos++;
  14. }
  15. cout<<"total negative numbers "<<count_neg<<" and positive number is "<<count_pos;
  16.  
  17. return 0;
  18. }

Answered by: asdasda on: Aug 10th, 2013

Code
  1. #include<conio.h>
  2. #include<iostream>
  3.  
  4. using namespace std;
  5.  
  6. int value(int a);
  7.  
  8. int main ()
  9. {
  10.     int a, num, count=0;
  11.    
  12.      cout<<"How many values: ";
  13.      cin>>num;
  14.    
  15.     getch ();
  16.    
  17.    
  18.    
  19. int value(int a);
  20.    
  21.    
  22.     for (a=1;a<=num;a++)
  23.     {
  24.    
  25.         cout<<"Enter value "<<a<<": ";
  26.         cout<<endl;
  27.         }
  28.        
  29.        
  30.         getch ();
  31.         return 0;
  32.         }
  33.        
  34.  

A=5;c=++a + ++a + ++a;what would be value of C after this statement and how does it come?If we have the codea=5;c=a++ + a++ + a++;what would be the value of C then?

Asked By: ashwini_nith | Asked On: Nov 22nd, 2007

Answered by: shweta gupta on: Jun 25th, 2014

It is completely dependent on the compiler to evaluate. we can see different behavior on different compilers. Example if u use turbo c the find the o/p of c=++a + ++a + ++a; is 24 and for c=a++ + a+...

Answered by: Jitendra Kumar on: Sep 8th, 2013

In the first case it gives answer 22 because it form a tree like structure and start from bottom i.e ++a and ++a in first ++a=6 and in the 2nd time ++a=7 and again aad take max[6,7] in the case of re-...

Function syntax

Asked By: ak.nextptr | Asked On: Jul 31st, 2012

String abc = showdata()["hello"]; can somebody explain what is use of ["hello"] after function call?

Answered by: shweta gupta on: Jun 25th, 2014

There is showdata is returning index .
example when it return 1 then abc="ello";

Answered by: jbode on: Aug 6th, 2012

C doesn't have a String data type, unless that supposed to be a typedef for something. Having said that, I think this is taking advantage of the fact that array indexing in C is commutative; IOW, "...

Program to print all prime numbers btw 1 to 100

Asked By: Pavani Shiny | Asked On: Nov 17th, 2013

C Program to print all prime numbers btw 1 to 100..
pls explain the program: What is if(p)??

Code
  1. #include
  2. #include
  3. int main()
  4. {
  5.  int num,n,div,p;
  6.  printf("Enter any number: ");
  7.  scanf("%d", &num);
  8.  for(n=2; n<=num; n++)
  9.  {
  10.   for(div=2; div  {
  11.    if(n%div==0)
  12.    {
  13.      p=0;
  14.      break;
  15.    }
  16.    p=1;
  17.   }
  18.   if(p)
  19.     printf("    %d",n);
  20.  }
  21.  getch();
  22.  
  23. }

Answered by: shweta gupta on: Jun 25th, 2014

Code
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. for(int i=1;i<=100;i++){
  5.         int flag=0;
  6.         if(i/2==0||i/2==1)
  7.         {
  8.                 cout<<"prime"<<i<<endl;
  9.                 continue;
  10.         }
  11.         for(int j=2;j<=i/2;j++){
  12.                 if(i%j==0){flag=0; break;}
  13.                 else flag=1;
  14.         }
  15.         if(flag){
  16.                 cout<<"prime "<<i<<endl;
  17.         }
  18. }
  19.  
  20. return 0;
  21. }
Code
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. for(int i=1;i<=100;i++){
  5.         int flag=0;
  6.         if(i/2==0||i/2==1)
  7.         {
  8.                 cout<<"prime"<<i<<endl;
  9.                 continue;
  10.         }
  11.         for(int j=2;j<=i/2;j++){
  12.                 if(i%j==0){flag=0; break;}
  13.                 else flag=1;
  14.         }
  15.         if(flag){
  16.                 cout<<"prime "<<i<<endl;
  17.         }
  18. }
  19.  
  20. return 0;
  21. }

Reverse string stored in pointer array

Asked By: vishv | Asked On: Nov 2nd, 2010

Write a C program to reverse the strings stored in the following array of pointers to strings char *s[]={"to err is human..", "but to really mess things up", "one needs to learn c!!" };

Answered by: Chentra HD on: Jun 21st, 2014

I can not run on Dev++?

Answered by: rocking.piyush on: Feb 22nd, 2011

#include <stdio.h>#include <string.h>void reverse (char *);main(){ char *s[] = {     "To err is human...",     "But to...

We have a 2 arrays e.G. Arr1[]={2,3,4,4,5,6,7} , arr2[]={1,2,2,4,6,8,8} . Assuming that both the arrays are sorted , if we want to write a program to find common numbers present in both arrays , how do...

Asked By: Ajay Kanse | Asked On: Aug 11th, 2007

Answered by: jbode on: Jun 19th, 2014

Assuming both arrays are sorted in ascending order, this is pretty easy to do in a single loop with two array counters. Start both counters at zero. Compare array elements at their respective counte...

Answered by: Meghraj on: Jun 14th, 2014

Well check for how many 1s,2s, upto 9s in both the arrays and minimum of a particular digit(from 1 to 9) in an array will be the common numbers of that particular digit. we will check upto 9 in both arrays for total common numbers.

C pyramid program

Asked By: DIPEN | Asked On: Jul 22nd, 2011

1 1 2 2 1 2 2 3 3 1 2 2 3 3 4 4 how to create this pyramid using C

Answered by: varun pujara on: Jun 18th, 2014

1 12 123 1234

Answered by: Sooraj Kumar on: Aug 3rd, 2011

Pyramid is answered in following code

Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3. main()
  4. {
  5. int i,j;
  6. clrscr();
  7. for(i=1;i<=4;i++)
  8. {
  9.  for(j=1;j<=i;j++)
  10.  {
  11.   printf("%d    ",j);
  12.   if(j!=1)
  13.   printf("%d    ",j);
  14.  }
  15. ");
  16. }
  17. getch();
  18. }

C is a structural or highlevel or middle level language which one is correct answer

Asked By: suchi | Asked On: Feb 3rd, 2006

Answered by: JOSNA JOSEPH on: Jun 10th, 2014

Yes C is a middle level language since it have both the features of low level and high level language. also C can be directly converted to low level, using C compiler. No other interpreter is needed...

Answered by: aswini on: Sep 25th, 2011

C is a high level procedure oriented structured programming language

What is the difference between structure and union?

Asked By: pawan aray | Asked On: Feb 8th, 2006

Answered by: Nidhi.saradhara on: May 5th, 2014

The difference between Union and structure is the structure is occupied a memory to all member in the structure but union is occupied to memory in largest member in union

Answered by: sendhil on: Aug 14th, 2011

Structure has different memory location but union has the same memory location while using the structure , struct is the keyword and here union is the keyword

If the following program (myprog) is run from the command line as myprog friday tuesday Sunday, what would be the output? main(int argc, char *argv[]) { printf("%c",*++argv[1]); } a) r b) f...

Asked By: Interview Candidate | Asked On: Jul 7th, 2005

Answered by: Amber Bhardwaj on: Apr 15th, 2014

For example, the command line gcc -o myprog myprog.c would result in the following values internal to GCC: "c argc 4 argv[0] gcc argv[1] -o argv[2] myprog argv[3] myprog.c ...

Answered by: nirupa on: Feb 22nd, 2008

The answer is a) r as argv[1] is fridayand argv[0] is myprog

How do I design an algorithm to check if a number is an armstrong number?

Asked By: Moses Iisa | Asked On: Apr 19th, 2006

Answered by: jbode on: Mar 7th, 2014

First, count up the number of digits in the candidate value; an easy way to do this is take the floor value of the log of the number and add 1 (for example, floor(log10(1234)) = 3, so 3 + 1 = 4 digits...

Answered by: Kapil S Shinde on: Feb 25th, 2014

"c start Accept num noOfDigit=calculate number of digits //use counting digit function while(num!=0) { remainder=inum%10; sum=sum+pow(remainder,noOfDigit); //use power func...

Output of a++ + ++a + a++

Asked By: crackboy | Asked On: Feb 9th, 2008

What is the answer of a++ + ++a + a++ int a=5;c = a++ + ++a + a++;//compiler produces the answer 28!!!//how

Answered by: anudeep jaini on: Feb 18th, 2014

19

Answered by: phani on: Jan 3rd, 2014

C=19 and a=8

What is result for of this C code block?

Asked By: jyotirmoyy | Asked On: Sep 3rd, 2011

What is the result main() { int x=15; printf("%d %d %d",x!=15,x=20,x

Answered by: jbode on: Feb 18th, 2014

The behavior is undefined; the arguments to printf aren't guaranteed to be evaluated in any particular order. The *result* of each expression is guaranteed to be passed in the order specified, but th...

Answered by: suresh on: Feb 14th, 2014

1 20 20

What is the output of the following program:

Asked By: lalithakasiraj | Asked On: Dec 15th, 2012

Code
  1. int main()
  2. {
  3. char a = 120, b = 140;
  4. int i;
  5. i = a + b;
  6. printf("%d", i);
  7. return 0;
  8. }
a) 260 b) 0 c) -1 d) 1

Answered by: Surajsingh Rajput on: Feb 12th, 2014

The answer is 4. because range of char is -128 to 127 so at 140 it get considered as 127,-128,-127,-126,....,-116.
so 120+(-116)=4

Answered by: ish mahajan on: Jan 16th, 2014

260

Is it possible to write a C program without semicolons?

Asked By: kamba | Asked On: Nov 29th, 2007

Answered by: prasanna on: Dec 4th, 2013

Max and min program without semicolon

Answered by: Manali on: Sep 18th, 2011

Code
  1. #include<stdio.h><br /><br />void main()<br /><br /> {<br /><br />   if(printf("no semicolon"))<br /><br /> {}<br /><br /> }

First | Prev | | Next | Last Page

 

 

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.