C Programming Interview Questions Set 9

Categories: C Programming language

Write a program to print factorial of given number using recursion?

#include<stdio.h>      

#include<conio.h>      

 long factorial(int n)    // function to calculate the factorial of a given number.   

{      

  if (n == 0)      

    return 1;      

else      

return(n * factorial(n-1));    //calling the function recursively.  

}      

 void main()      

{      

  int number;    //declaration of variables.  

  long fact;      

 clrscr();      

  printf("Enter a number: ");      

scanf("%d", &number);       

 fact = factorial(number);    //calling a function.  

printf("Factorial of %d is %ld\n", number, fact);      

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

}  


 Write a program to check Armstrong number in C?

#include<stdio.h>      

#include<conio.h>      

main()      

{      

int n,r,sum=0,temp;    //declaration of variables.  

clrscr(); //It clears the screen.     

printf("enter the number=");      

scanf("%d",&n);      

temp=n;      

while(n>0)      

{      

r=n%10;      

sum=sum+(r*r*r);      

n=n/10;      

}      

if(temp==sum)      

printf("armstrong  number ");      

else      

printf("not armstrong number");      

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

}    


Write a program to reverse a given number in C?

#include<stdio.h>      

#include<conio.h>      

main()      

{      

int n, reverse=0, rem;    //declaration of variables.  

clrscr(); // It clears the screen.     

printf("Enter a number: ");      

scanf("%d", &n);      

while(n!=0)      

{      

     rem=n%10;      

     reverse=reverse*10+rem;      

     n/=10;      

}      

printf("Reversed Number: %d",reverse);      

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

}      

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.