# Basic C Programs for Technical Interviews

1. Swap two no’s without using third variable. 2. Reverse a given number. 3. Greatest in 3 numbers. 4. Given no is even or odd. 5. Display first 10 natural no & their sum. 6. Factorial of a number. 7. Given no is a prime no or not. 8. Add two number using pointers. 9. Multiplication of two matrices. 10. Reverse a number using pointer. 11. Swap two numbers using functions. 12. Factorial of a number using functions. 13. Call by value. 14. Call by reference. 15. Factorial of a number using recursion. 16. String is palindrome or not. 1. Program to show swap of two no’s without using third variable.
#include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf("enter value for a & b: "); scanf("%d%d",&a,&b); a=a+b; b=a-b; a=a-b; printf("after swapping the value of a & b: %d %d",a,b); getch(); }

2. Program to reverse a given number:
#include<stdio.h> #include<conio.h>

if((c>a)&&(c>b)) printf("c is greatest").a. if((a>b)&&(a>c)) printf("a is greatest").void main() { int n. if((b>c)&&(b>a)) printf("b is greatest"). b & c: ").h> #include<conio.&c). printf("enter value of a. n=n/10. #include<stdio. r=r*10+a.h> void main() { int n.r=0. while(n>=1) { a=n%10.&n). clrscr(). scanf("%d%d%d". #include<stdio.&a.&b. Program to find greatest in 3 numbers. } 3.r). clrscr(). printf("enter any no: ").h> #include<conio. getch(). Program to find whether given no is even or odd. } printf("reverse=%d". clrscr(). getch(). .h> void main() { int a. } 4. scanf("%d".c.b. printf("enter any no to get its reverse: ").

i<=10. else printf("no is odd").&n).h> void main() { int i.scanf("%d". scanf("%d". printf("Enter any no: "). for(i=1.i.fact=1.i>=1. getch().i--) { fact=fact*i.h> #include<conio.i.i++) { printf("%d no is= %d\n".fact).sum=0. clrscr().sum).h> void main() { int n.&n). } printf("sum =%d".I). } . Program to display first 10 natural no & their sum. #include<stdio. } printf("Factorial=%d". if(n%2==0) printf("no is even"). #include<stdio. for(i=n. getch(). Program to find factorial of a number.h> #include<conio. getch(). clrscr(). sum=sum+i. } 5. } 6.

h> .&n).sum).n. clrscr(). printf("sum=%d".r=0.*p2. sum=*p1+*p2.h> #include<conio.h> void main() { int *p1. } 8. else printf("Not prime"). clrscr(). getch(). #include<stdio. printf("enter two no's: "). Program to find multiplication of two matrices. } if(r==0) printf("prime no"). #include<stdio. getch(). for(i=2.h> #include<conio.&*p2).h> void main() { int i.i++) { if(n%i==0) r=1. break.i<=n-1. #include<stdio. Program to find whether given no is a prime no or not. scanf("%d".h> #include<conio.sum. printf("Enter any no: "). } 9. scanf("%d%d".7. Program to add two number using pointers.&*p1.

j++) c[i][j]=a[i][j]*b[i][j].i<3.h> #include<conio. } printf("\n").j<2. for(i=0.i.j<2. Program to reverse a number using pointer. } for(i=0.h> void main() { int *n.j++) { printf(" %d ".j<2. for(i=0.i++) { for(j=0.void main() { int a[3][2]. printf("enter any no to get its reverse: ").i<3. clrscr().j++) scanf("%d".&a[i][j]). while(*n>=1) { .&*n).b[3][2].r=0. } getch(). } printf("enter value for 2 matrix: ").j<2. scanf("%d".j++) scanf("%d".i++) { for(j=0.c[3][2].i<3.a. printf("enter value for 1 matrix: "). #include<stdio. clrscr().&b[i][j]).i<3. } printf("matrix is\n"). } 10. for(i=0.i++) { for(j=0.j.i++) { for(j=0.c[i][j]).

a.h> #include<conio. #include<stdio.b). #include<stdio.int). getch(). clrscr(). } void swap(int a. getch().&a. int fact(int). int a. scanf("%d".b. clrscr(). printf("enter value for a&b: ").b). } 12. Program to swap two numbers using functions. } 11.f. Program to find factorial of a number using functions.&b). *n=*n/10. temp=a. b=temp. scanf("%d%d".a=*n%10. a=b.r.h> #include<conio.h> void main() { int a.int b) { int temp. printf("enter a no: "). r=r*10+a.h> void main() { void swap(int. } printf("reverse=%d". printf("after swapping the value for a & b is : %d %d".r). .&a). swap(a.

for(i=x.int y) { int temp.i--) fac=fac*i.h> void main() { int a.b).swap(). x=y. a=5. clrscr().i.. } int swap(int x.*aa. } int fact(int x) { int fac=1. swap(a.b). Program to show call by value.swap(). clrscr(). a=5. printf("\nvalue of a =%d & b=%d after swap". printf("factorial= %d". printf("value of a=%d & value of b=%d before swap ". #include<stdio.i>=1.a. y=temp. getch().b. b=10. #include<stdio. getch().h> #include<conio. temp=x. } 14. Program to show call by reference. } 13. .f=fact(a).b. b=10. return(fac).h> void main() { int a.b).h> #include<conio.a.*bb.f).

} 15. Program to find factorial of a number using recursion. printf("enter number: ").&n). printf("value of a= %d & value of b=%d before swap".h> void main() { int n. swap(aa. getch().int *y) { int temp.fact(n)). temp=*x.n.b). else printf("%d!=%d".b).h> #include<conio. bb=&b. scanf("%d". clrscr(). } int fact(int x) { if(x==0) return 1.aa=&a. *y=temp. getch(). if(n<0) printf("invalid number"). } int swap(int *x.bb). } . #include<stdio. else return(x*fact(x-1)).a. *x=*y.a. printf("\nvalue of a=%d & b=%d after swap".

s2)==0) printf("string is a palindrome"). clrscr(). scanf("%s". Program to find whether a string is palindrome or not.s1). strrev(s2).s2[20]. else printf("not a palindrome string").16. getch(). strcpy(s2. #include<stdio.s1).h> void main() { char s1[20]. if(strcmp(s1.h> #include<conio. printf("enter a string: "). } .