C Programming Interview Questions Set 8

Categories: C Programming language

Write a program to print "hello world" without using a semicolon?

#include<stdio.h>      

void main(){      

 if(printf("hello world")){} // It prints the ?hello world? on the screen.  


 Write a program to swap two numbers without using the third variable?

#include<stdio.h>      

#include<conio.h>      

main()      

{      

int a=10, b=20;    //declaration of variables.  

clrscr();        //It clears the screen.  

printf("Before swap a=%d b=%d",a,b);        

      

a=a+b;//a=30 (10+20)       

b=a-b;//b=10 (30-20)      

a=a-b;//a=20 (30-10)      

      

printf("\nAfter swap a=%d b=%d",a,b);      

getch();      

}  


Write a program to print Fibonacci series without using recursion?

#include<stdio.h>    

#include<conio.h>    

void main()    

{    

 int n1=0,n2=1,n3,i,number;    

 clrscr();    

 printf("Enter the number of elements:");    

 scanf("%d",&number);    

 printf("\n%d %d",n1,n2);//printing 0 and 1    

    

 for(i=2;i<number;++i)//loop starts from 2 because 0 and 1 are already printed    

 {    

  n3=n1+n2;    

  printf(" %d",n3);    

  n1=n2;    

  n2=n3;    

 }    

getch();    

}   


Write a program to check prime number in C Programming?

#include<stdio.h>      

#include<conio.h>      

void main()      

{      

int n,i,m=0,flag=0;    //declaration of variables.  

clrscr();    //It clears the screen.  

printf("Enter the number to check prime:");      

scanf("%d",&n);      

m=n/2;      

for(i=2;i<=m;i++)      

{      

if(n%i==0)      

{      

printf("Number is not prime");      

flag=1;      

break;    //break keyword used to terminate from the loop.  

}      

}      

if(flag==0)      

printf("Number is prime");      

getch();    //It reads a character from the keyword.  

}  


 Write a program to check palindrome number in C Programming?

#include<stdio.h>    

#include<conio.h>    

main()    

{    

int n,r,sum=0,temp;    

clrscr();    

printf("enter the number=");    

scanf("%d",&n);    

temp=n;    

while(n>0)    

{    

r=n%10;    

sum=(sum*10)+r;    

n=n/10;    

}    

if(temp==sum)    

printf("palindrome number ");    

else    

printf("not palindrome");    

getch();    

}    

Top Blogs
C Functions ! What is a Function Published at:- Types of Function in C ! Library Function in C ! User Defined Function In C ! Function Definition Published at:- Functions that return multiple values -C Example Published at:- Functions with arguments and return values -C Examples Published at:- Functions with arguments and no return values. Published at:- Example of Function with no return type and no argument Published at:- Loops in C Published at:- Structure in C: Introduction Published at:- C Memory Management ! Dynamic memory allocation Published at:- Learn C Programming language with example Published at:- C Interview Questions And Answers Published at:- What values are printed when we run following? Published at:- C Program example: Input a number and print sum of its digits Published at:- Pointer declaration in C ,Address operator Published at:- C Language Interview Question and Answers Published at:- Benefits of C language over other programming languages Published at:- History of C Language : Introduction to C Programming Language Published at:- How does C Programming Language Work Published at:- Importance of C Programming Language Published at:- Input and Output Functions in C Published at:- Introduction to Implementation of Queue using Linked List Published at:- First C Program Published at:- Inception Of C Language Tutorial for Beginners Published at:- The C Compiler work in C language and its important Published at:- Program Structure with “Hello World” Example Published at:- C Programming Interview Questions Set 1 Published at:- C Programming Interview Questions Set 2 Published at:- C Programming Interview Questions Set 3 Published at:- C Programming Interview Questions Set 4 Published at:- C Programming Interview Questions Set 5 Published at:- C Programming Interview Questions Set 6 Published at:- C Programming Interview Questions Set 7 Published at:- C Programming Interview Questions Set 8 Published at:- C Programming Interview Questions Set 9 Published at:-
R4R.co.in Team
The content on R4R is created by expert teams.