Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

Created By Mukesh Badgujar

C-PROGRAMS
1. TO PRINT HELLO WORD PROGRAM
#include<conio.h>
#include<stdio.h> //header files
void main()//function
{
clrscr(); //to clear previus screen.
printf("Hello Word Program");//use for print information on screen.
getch();//to get a character, or stop window.
}
2. ADDITION PROGRAM
#include<conio.h>
#include<stdio.h>
void main()
{
int a,b,sum;//variable decleared integer type.
clrscr();
a=5;
b=5;
printf("\nthe two numbers are a=%d b=%d",a,b);
sum=a+b; //sum of a+b is go into sum variable.
printf("\nthe sum is %d",sum);//then we write here sum.
getch();
}
3. ADDITION PROGRAM
#include<conio.h>
#include<stdio.h>
void main()
{
int a,b,sum; clrscr();
printf("Enter two number for sum");
scanf("\n%d%d",&a,&b); //\n use for new line,&a &b
//are address of enterd numbers in memory location.
printf("\nthe entered numbers are a=%d b=%d",a,b);
sum=a+b;
printf("\nthe sum is %d",sum);
getch();
}
4. CALCULATOR PROGRAM
#include<conio.h>
#include<stdio.h>
MSB PRODUCTION 1
Mo. No. - 9922108881
Created By Mukesh Badgujar

void main()
{
int a,b,sum;clrscr();
printf("enter two numbers for addition\n");
scanf("%d%d",&a,&b);
sum=a+b;
printf("\nthe answer is %d",sum);

printf("\nenter two numbers for substraction\n");


scanf("%d%d",&a,&b);
sum=a-b;
printf("\nthe answer is %d",sum);

printf("\nenter two numbers for multiplication\n");


scanf("%d%d",&a,&b);
sum=a*b;
printf("\nthe answer is %d",sum);

printf("\nenter two numbers for division\n");


scanf("%d%d",&a,&b);
sum=a/b;
printf("\nthe answer is %d",sum);

printf("\nenter two numbers for modulo\n");


scanf("%d%d",&a,&b);
sum=a%b;
printf("\nthe answer is %d",sum);
getch();
}
5. SWAPPING OF TWO NUMBERS (using third variable)
#include<conio.h>
#include<stdio.h>
void main()
{
int a,b,c;clrscr();
printf("Enter two number for swapping");
scanf("%d%d",&a,&b);
printf("\nNumber before swapping are a=%d b=%d",a,b);
c=a;//value of a goes in c.(a=5,b=4)/ c=a ->c=5
a=b;//value of b goes in a. / a=b ->a=4
b=c;//value of c goes in b. / b=c ->b=5
printf("\nNumbers after swapping are a=%d b=%d",a,b);
getch();
}

MSB PRODUCTION 2
Mo. No. - 9922108881
Created By Mukesh Badgujar

6. SWAPPING OF TWO NUMBERS (without using third variable)


#include<conio.h>
#include<stdio.h>
void main()
{
int a,b;clrscr();
printf("Enter two number for swapping");
scanf("%d%d",&a,&b);
printf("\nNumber before swapping are a=%d b=%d",a,b);
a=a+b;//value of a+b goes in a.(a=5,b=4)/a=a+b->a=9
b=a-b;//value of b goes in a. /b=a-b->b=9-4=5
a=a-b;//value of c goes in b. /a=a-b->a=9-5=4
printf("\nNumbers after swapping are a=%d b=%d",a,b);
getch();
}
7. TO CHECK LEAP YEAR
#include<conio.h>
#include<stdio.h>
void main()
{
int year;clrscr();
printf("Enter year to check leap year");
scanf("%d",&year);
if(year%4==0)//year modulo 4 is equal to 0 then
{ //condition will true,then if block execute.
printf("%d year is leap year",year);
}
else
{ //if condition is false then else block execute.
printf("%d year is not leap year",year);
}
getch();
}
8. BITWISE OPRATOR
#include<conio.h>
#include<stdio.h>
void main()
{
int x=5,y=8;
int A,B,C,D,E;clrscr();
A=x&y;
B=x/y;
C=x^y;
D=~x;
E=~y;

MSB PRODUCTION 3
Mo. No. - 9922108881
Created By Mukesh Badgujar

printf("Bitwise AND A=%d",A);


printf("\nBitwise OR B=%d",B);
printf("\nBitwise EX-OR C=%d",C);
printf("\nBitwise NOT D=%d",D);
printf("\nBitwise NOT E=%d",E);
getch();
}
9. SIMPLE IF…ELSE STATEMENT
#include<conio.h>
#include<stdio.h>
void main()
{
int a,b;
clrscr();
printf("Enter two numbers");
scanf("%d%d",&a,&b);
if(a<b)
{
printf("It is If block");
}
else
{
printf("It is else block");
}
getch();
}
10. GRETER NUMBER BETWEEN TWO NUMBERS
#include<conio.h>
#include<stdio.h>
void main()
{
int a,b;
clrscr();
printf("Enter two numbers to find greter number");
scanf("%d%d",&a,&b);
if(a>b)
{
printf("%d a is greter number",a);
}
else if(b>a)
{
printf("%d b is greter number",b);
}
getch();
}

MSB PRODUCTION 4
Mo. No. - 9922108881
Created By Mukesh Badgujar

11. GRETER NUMBER BETWEEN THREE NUMBERS


#include<conio.h>
#include<stdio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter three numbers to determing greater number");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
{
printf("%d a is greater",a);
}
else if(b>a&&b>c)
{
printf("%d b is greater",b);
}
else if(c>a&&c>b)
{
printf("%d c is greater",c);
}
getch();
}
12. SWITCH STATEMENT (1 -> one)
#include<conio.h>
#include<stdio.h>
void main()
{
int n;
clrscr();
printf("enter number between 1 to 4");
scanf("%d",&n);
switch(n)
{
case 1: printf("ONE");
break;
case 2: printf("TWO");
break;
case 3: printf("THREE");
break;
case 4: printf("FOUR");
break;
default: printf("numberis not in range ");
break;
}

MSB PRODUCTION 5
Mo. No. - 9922108881
Created By Mukesh Badgujar

getch();
}
13. SWITCH STATEMENT (VOWEL)
#include<conio.h>
#include<stdio.h>
void main()
{
char n;
clrscr();
printf("enter ");
scanf("%c",&n);
switch(n)
{
case 'a': printf("vowel");
break;
case 'e': printf("vowel");
break;
case 'i': printf("vowel");
break;
case 'o': printf("vowel");
break;
case 'u': printf("vowel");
break;
default: printf("numberis not in range ");
break;
}
getch();
}
14. CHECK ODD OR EVEN
#include<conio.h>
#include<stdio.h>
void main()
{
int a,b;
clrscr();
printf("Enter a numbers to check odd or even");
scanf("%d",&a);
if(a%2==0)
{
printf("it is even number");
}
else
{
printf("it is odd number");
}

MSB PRODUCTION 6
Mo. No. - 9922108881
Created By Mukesh Badgujar

getch();
}
15. TO CHECK NEGATIVE OR POSITIVE
#include<conio.h>
#include<stdio.h>
void main()
{
int a,b;
clrscr();
printf("Enter a numbers to check positive or negative");
scanf("%d",&a);
if(a>0)
{
printf("it is positive number");
}
else if(a<0)
{
printf("it is negative number");
}
else if(a==0)
{
printf("it is zero number");
}
getch();
}
16. WHILE LOOP
#include<conio.h>
#include<stdio.h>
void main()
{
int n;
clrscr();
printf("Enter a number to print more times");
scanf("%d",&n);
while(n>0)
{
printf("\nIMRD");
n--;
}
getch();
}
17. DO….WHILE LOOP
#include<conio.h>
#include<stdio.h>
void main()

MSB PRODUCTION 7
Mo. No. - 9922108881
Created By Mukesh Badgujar

{
int n;
clrscr();
printf("Enter a number to print more times");
scanf("%d",&n);
do
{
printf("\nIMRD");
n--;
}
while(n>0);
getch();
}
18. FOR LOOP
#include<conio.h>
#include<stdio.h>
void main()
{
int start,end,i;
clrscr();
printf("Enter a number to start series from");
scanf("%d",&start);
printf("Enter a number to end series from");
scanf("%d",&end);
for(i=start;i<=end;i++)
{
printf("\n%d",i);
}
getch();
}
19. SQUARE OF ANY REAL NUMBER
#include<conio.h>
#include<stdio.h>
void main()
{
int a,b;
clrscr();
printf("Enter a number for square");
scanf("%d",&a);
b=a*a;
printf("Square is %d",b);
getch();
}
20. SUM OF EVEN NUMBER IN RANGE
#include<conio.h>

MSB PRODUCTION 8
Mo. No. - 9922108881
Created By Mukesh Badgujar

#include<stdio.h>
void main()
{
int i=0,sum=0,n;
clrscr();
printf("Enter a range to sum of even numbers");
scanf("%d",&n);
while(i<=n)
{
if(i%2==0)
{
sum=sum+i;
}
i++;
}
printf("Sum of even numbers is %d",sum);
getch();
}
21. SUM OF ODD NUMBER IN RANGE
#include<conio.h>
#include<stdio.h>
void main()
{
int i=0,sum=0,n;
clrscr();
printf("Enter a range to sum of odd numbers");
scanf("%d",&n);
while(i<=n)
{
if(i%2!=0)
{
sum=sum+i;
}
i++;
}
printf("Sum of even numbers is %d",sum);
getch();
}
22. RESULT BY MARKS
#include<conio.h>
#include<stdio.h>
void main()
{
int a;
clrscr();

MSB PRODUCTION 9
Mo. No. - 9922108881
Created By Mukesh Badgujar

printf("Enter your marks for result");


scanf("%d",&a);
if(a>69&&a<=100)
{
printf("YOU ARE IN DISTINCTION");
}
else if(a>59&&a<70)
{
printf("1st CLASS");
}
else if(a<60&&a>34)
{
printf("2nd CLASS");
}
else if(a<35&&a>=0)
{
printf("YOU ARE FAIL");
}
getch();
}
23. FACTORIAL
#include<conio.h>
#include<stdio.h>
void main()
{
int fact=1,num,i;
clrscr();
printf("Enter number for factorial");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
fact=fact*i;
}
printf("factorial is %d",fact);
getch();
}
24. AMSTRONG NUMBER
#include<stdio.h>
#include<conio.h>
void main()
{
int num,rev=0,rem,n1;
clrscr();
printf("Enter number to find armstrong number");
scanf("%d",&num);//153

MSB PRODUCTION 10
Mo. No. - 9922108881
Created By Mukesh Badgujar

n1=num;
while(num>0)
{
rem=n1%10;
n1=n1/10;;
rev=rev+(rem*rem*rem);
}
if(rev==num)
{
printf("the armstrong number is %d",num);
}
else
{
printf("the number is not armstrong ");
}
getch();
}
25. SUM OF DIGIT
#include<stdio.h>
#include<conio.h>
void main()
{
int num,sum=0,rem;
clrscr();
printf("Enter number to sum of digit");
scanf("%d",&num);
while(num>0)
{
rem=num%10;
num=num/10;;
sum=sum+rem;
}
printf("sum of digit is number is %d",sum);
getch();
}

25.1. REVERSE NUMBER

#include<stdio.h>
#include<conio.h>
void main()
{
int num,temp,rev=0,rem;
clrscr();
printf("Enter number to reverse it");
scanf("%d",&num);
MSB PRODUCTION 11
Mo. No. - 9922108881
Created By Mukesh Badgujar

temp=num;
while(num!=0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
}
printf("REVERSE number is %d",rev);
getch();
}
26. PALINDROME NUMBER
#include<stdio.h>
#include<conio.h>
void main()
{
int num,temp,rev=0,rem;
clrscr();
printf("Enter number to check palindrome");
scanf("%d",&num);
temp=num;
while(num!=0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
}
if(temp==rev)
{
printf("palindrome number is %d",temp);
}
else
{
printf("%d it is not palindorme number",temp);
}
getch();
}
27. PRIME NUMBER
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,p=1;;
clrscr();
printf("Enter the number\n");
scanf("%d",&n);

MSB PRODUCTION 12
Mo. No. - 9922108881
Created By Mukesh Badgujar

for(i=2;i<n;i++)
if(n%i==0)
{
p=0;
break;
}
if(p==1)
{
printf("It is prime number");
}
else
{
printf("It is not prime number");
}
getch();
}
28. LEAP YEAR BY CHOICE Y OR N
#include<conio.h>
#include<stdio.h>
void main()
{
int year,f=0;
char n;
clrscr();
while(f==0)
{
printf("\n\nDo you want to check year is leap or not press y or n\n");
scanf("\t%c",&n);
switch(n)
{
case 'y':printf("\nEnter the year");
scanf("\n\t%d",&year);
if(year==4)
{
printf("\n%d year is leap year",year);
}
else
{
printf("\n%d year is not leap year",year);
}
break;
case 'n':f=1;
exit(0);
}
}

MSB PRODUCTION 13
Mo. No. - 9922108881
Created By Mukesh Badgujar

getch();
}
29. RANGE OF PRIME NUMBER
#include<stdio.h>
#include<conio.h>
void main()
{
int r1,r2,i,p,f,j;
clrscr();
printf("Enter the range to find prime number betwen two interval\n");
scanf("%d%d",&r1,&r2);
for(i=r1;i<=r2;i++)
{
f=0;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
f=1;
break;
}
}
if(f==0)
{
printf("\n%d \n",i);
}
}
getch();
}
30. FIBONACCI SERIES
#include<conio.h>
#include<stdio.h>
void main()
{
int a,b=0,c=1,e,i,d;
clrscr();
printf("Enter number to find fibonacci series");
scanf("%d",&a);
printf("\nfirst term is %d\n",a);
for(e=0;e<a;e++)
{
if(e<=i)
d=e;
else
{

MSB PRODUCTION 14
Mo. No. - 9922108881
Created By Mukesh Badgujar

d=b+c;
b=c;
c=d;
}
printf("%d\n",d);
}
getch();
}
31. SERIES OF AMSTRONG NUMBER
#include<stdio.h>
#include<conio.h>
void main()
{
int num,rev,rem,i,n;
clrscr();
printf("Enter range to find armstrong number");
scanf("%d",&n);//153
for(i=1;i<=n;i++)
{
num=i;
rev=0;
while(num!=0)
{
rem=num%10;
num=num/10;
rev=rev+(rem*rem*rem);
}
if(i==rev)
{
printf("\nthe armstrong number is %d",i);
}
}
getch();
}
32. FIND SIMPLE INTREST
#include<conio.h>
#include<stdio.h>
void main()
{
float p,r,n,si;
clrscr();
printf("\n Enter amount");
scanf("%f",&p);
printf("\n Enter rate");
scanf("%f",&r);

MSB PRODUCTION 15
Mo. No. - 9922108881
Created By Mukesh Badgujar

printf("\n Enter time");


scanf("%f",&n);
si=(p*r*n)/100;
printf("\n %f is the simple intrest",si);
getch();
}
33. FIND COMPOUND INTREST
#include<conio.h>
#include<stdio.h>
void main()
{
float amount,time,ci;
long float rate;
clrscr();
printf("\n Enter amount");
scanf("%f",&amount);
printf("\n Enter rate");
scanf("%f",&rate);
printf("\n Enter time");
scanf("%f",&time);
ci=amount*(pow((1+rate/100),time))-1;
printf("\n %f is the compound intrest",ci);
getch();
}
34. SWAPPING BY CALL BY VALUE
#include<conio.h>
#include<stdio.h>
void swap(int x,int y);
int main()
{
int a,b;
clrscr();
printf("Enter two number for swapping");
scanf("%d%d",&a,&b);
printf("Entered numbers are a=%d b=%d",a,b);
swap(a,b);
getch();
}
void swap(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
printf("\nNumber after swapping are a=%d b=%d ",x,y);

MSB PRODUCTION 16
Mo. No. - 9922108881
Created By Mukesh Badgujar

}
35. ADDITION BY CALLING FUNCTION
#include<conio.h>
#include<stdio.h>
void add(int x,int y);
int main()
{
int a,b;
clrscr();
printf("Enter two number for add");
scanf("%d%d",&a,&b);
printf("Entered numbers are a=%d b=%d",a,b);
add(a,b);
getch();
}
void add(int x,int y)
{
int c;
c=x+y;
printf("\nThe answer is %d ",c);
}
36. POINTER USING SWAPPING
#include<conio.h>
#include<stdio.h>
void swap(int *a,int *b);
void main()
{
int m,n;
clrscr();
printf("Enter two number for swapping");
scanf("%d%d",&m,&n);
printf("Two number before swapping are a=%d b=%d",m,n);
swap(&m,&n);
}
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
printf("\n Value after swapping are a=%d b=%d",*a,*b);
getch();
}
37. SORTING BY REVERSE(DESENDING ORDER)
#include<conio.h>

MSB PRODUCTION 17
Mo. No. - 9922108881
Created By Mukesh Badgujar

#include<stdio.h>
void main()
{
int num[20],j,i,size;
clrscr();
printf("\n\tEnter size of array");
scanf("%d",&size);
printf("\n\tEnter element to arrang in desending order");
for(i=0;i<size;i++)
{
scanf("%d",&num[i]);
}
printf("\n\t Array element befor sort");
for(i=0;i<size;i++)
{
printf("\n\t");
printf("%d",num[i]);
}
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
if(num[i]>num[j])
{
int temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
printf("\n\tElement after sorting");
for(i=0;i<size;i++)
{
printf("\n\t");
printf("%d",num[i]);
}
getch();
}
38. SORTING BY REVERSE(ASSENDING ORDER)
#include<conio.h>
#include<stdio.h>
void main()
{
int num[20],j,i,size;
clrscr();

MSB PRODUCTION 18
Mo. No. - 9922108881
Created By Mukesh Badgujar

printf("\n\tEnter size of array");


scanf("%d",&size);
printf("\n\tEnter element to arrang in assending order");
for(i=0;i<size;i++)
{
scanf("%d",&num[i]);
}
printf("\n\t Array element befor sort");
for(i=0;i<size;i++)
{
printf("\n\t");
printf("%d",num[i]);
}
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
if(num[i]<num[j])
{
int temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
printf("\n\tElement after sorting");
for(i=0;i<size;i++)
{
printf("\n\t");
printf("%d",num[i]);
}
getch();
}
39. SEARCH ARRAY ELEMENT IN RANGE
#include<conio.h>
#include<stdio.h>
void main()
{
int p,n;
int num[20],size,i;
p=0;
clrscr();
printf("\n\tEnter size of array");
scanf("%d",&size);
printf("\n\tEnter array elements");

MSB PRODUCTION 19
Mo. No. - 9922108881
Created By Mukesh Badgujar

for(i=0;i<size;i++)
{
scanf("%d",&num[i]);
}

printf("\n\t Enter element to search in range");


scanf("%d",&n);
for(i=0;i<size;i++)
{
if(n==num[i])
{
p=1;
break;
}
}
if(p==1)
{
printf("\n\t%d element is found",n);
}
else
{
printf("\n\t%d element is not found ",n);
}
getch();
}
40. FIND MAX AND MIN ARRAY
#include<conio.h>
#include<stdio.h>
void main()
{
int max,min;
int num[20],size,i;
clrscr();
printf("\n\tEnter size of array");
scanf("%d",&size);
printf("\n\tEnter size of array element to find max and min array");
for(i=0;i<size;i++)
{
scanf("%d",&num[i]);
}
max=num[0];
min=num[0];
for(i=0;i<size;i++)
{
if(num[i]>max)

MSB PRODUCTION 20
Mo. No. - 9922108881
Created By Mukesh Badgujar

{
max=num[i];
}
if(num[i]<min)
{
min=num[i];
}
}
printf("\n\tMax element is %d",max);
printf("\n\tMin element is %d",min);
getch();
}
41. MATRIX ADDITION
#include<conio.h>
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],c[10][10];
int i,j,m,n,p,q;
clrscr();
printf("\n\tEnter row size of matrix A");
scanf("%d",&m);
printf("\n\tEnter row size of matrix A");
scanf("%d",&n);
printf("\n\tEnter matrix element");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n\tEnter row size of matrix B");
scanf("%d",&p);
printf("\n\tEnter row size of matrix B");
scanf("%d",&q);
printf("\n\tEnter matrix element");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\n\tElements in matrix A are");

MSB PRODUCTION 21
Mo. No. - 9922108881
Created By Mukesh Badgujar

for(i=0;i<m;i++)
{
printf("\n\n");
for(j=0;j<n;j++)
{
printf("%d",a[i][j]);
printf("\t");
}
}
printf("\n\tElements in matrix B are");
for(i=0;i<p;i++)
{
printf("\n\n");
for(j=0;j<q;j++)
{
printf("%d",b[i][j]);
printf("\t");
}
}
if(m==p&&n==q)
{
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("Addition of matrix is");
for(i=0;i<p;i++)
{
printf("\n\n");
for(j=0;j<q;j++)
{
printf("%d",c[i][j]);
printf("\t");
}
}
}
else
{
printf("Please enter equal size of matrix");
}
getch();
}

MSB PRODUCTION 22
Mo. No. - 9922108881
Created By Mukesh Badgujar

42. MATRIX SUBSTRACTION


#include<conio.h>
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],c[10][10];
int i,j,m,n,p,q;
clrscr();
printf("\n\tEnter row size of matrix A");
scanf("%d",&m);
printf("\n\tEnter row size of matrix A");
scanf("%d",&n);
printf("\n\tEnter matrix element");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n\tEnter row size of matrix B");
scanf("%d",&p);
printf("\n\tEnter row size of matrix B");
scanf("%d",&q);
printf("\n\tEnter matrix element");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\n\tElements in matrix A are");
for(i=0;i<m;i++)
{
printf("\n\n");
for(j=0;j<n;j++)
{
printf("%d",a[i][j]);
printf("\t");
}
}
printf("\n\tElements in matrix B are");
for(i=0;i<p;i++)
{

MSB PRODUCTION 23
Mo. No. - 9922108881
Created By Mukesh Badgujar

printf("\n\n");
for(j=0;j<q;j++)
{
printf("%d",b[i][j]);
printf("\t");
}
}
if(m==p&&n==q)
{
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=a[i][j]-b[i][j];
}
}
printf("SUBSTRACTION of matrix is");
for(i=0;i<p;i++)
{
printf("\n\n");
for(j=0;j<q;j++)
{
printf("%d",c[i][j]);
printf("\t");
}
}
}
else
{
printf("Please enter equal size of matrix");
}
getch();
}
43. TRANSPOSE OF MATRIX
#include<conio.h>
#include<stdio.h>
void main()
{
int a[10][10];
int i,j,m,n;
clrscr();
printf("\n\tEnter row size of matrix A");
scanf("%d",&m);
printf("\n\tEnter row size of matrix A");
scanf("%d",&n);

MSB PRODUCTION 24
Mo. No. - 9922108881
Created By Mukesh Badgujar

printf("\n\tEnter matrix element");


for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n\tElements in matrix A are");
for(i=0;i<m;i++)
{
printf("\n\n");
for(j=0;j<n;j++)
{
printf("%d",a[i][j]);
printf("\t");
}
}
printf("\n\tTranspose of matrix is");
for(i=0;i<m;i++)
{
printf("\n\n");
for(j=0;j<n;j++)
{
printf("%d",a[j][i]);
printf("\t");
}
}
getch();
}

44. MATRIX MULTIPLICATION


#include<conio.h>
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],c[10][10];
int i,j,m,n,p,q,sum,k;
clrscr();
printf("\n\tEnter row size of matrix A");
scanf("%d",&m);
printf("\n\tEnter row size of matrix A");
scanf("%d",&n);
printf("\n\tEnter matrix element");
for(i=0;i<m;i++)

MSB PRODUCTION 25
Mo. No. - 9922108881
Created By Mukesh Badgujar

{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n\tEnter row size of matrix B");
scanf("%d",&p);
printf("\n\tEnter row size of matrix B");
scanf("%d",&q);
printf("\n\tEnter matrix element");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\n\tElements in matrix A are");
for(i=0;i<m;i++)
{
printf("\n\n");
for(j=0;j<n;j++)
{
printf("%d",a[i][j]);
printf("\t");
}
}
printf("\n\tElements in matrix B are");
for(i=0;i<p;i++)
{
printf("\n\n");
for(j=0;j<q;j++)
{
printf("%d",b[i][j]);
printf("\t");
}
}
if(m==p&&n==q)
{
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
sum=0;

MSB PRODUCTION 26
Mo. No. - 9922108881
Created By Mukesh Badgujar

for(k=0;k<q;k++)
{
sum=sum+(a[i][k]*b[k][j]);
}
c[i][j]=sum;
}
}
printf("Multiplication of matrix is");
for(i=0;i<p;i++)
{
printf("\n\n");
for(j=0;j<q;j++)
{
printf("%d",c[i][j]);
printf("\t");
}
}
}
else
{
printf("Please enter equal size of matrix");
}
getch();
}
45. NUMBER TO WORDS
#include<conio.h>
#include<stdio.h>
void main()
{
char a[10][10]={"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"};
charb[10][10]={"ELEVEN","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN","SEVENTEEN"
,"EIGHTEEN","NINTEEN"};
char
c[10][10]={"TEN","TWENTY","THIRTY","FOURTY","FIFTY","SIXTY","SEVENTY","EIGHTY","NINTY"};
int no,t;
clrscr();
printf("\tEnter the number");
scanf("%d",&no);
printf("\t");
if(no<9999)
{
if(no>1000)
{
t=no/1000;
no=no%1000;

MSB PRODUCTION 27
Mo. No. - 9922108881
Created By Mukesh Badgujar

printf("%s THOUSAND",a[t-1]);
}
if(no>100)
{
t=no/100;
no=no%100;
printf(" %s HUNDRED AND ",a[t-1]);
}
if(no>=10 && no<20)
{
t=no/10;
printf(" %s",b[t-1]);
}
if(no>19 && no<=100)
{
t=no/10;
no=no%10;
printf("%s",c[t-1]);
}
if(no<10)
{
printf(" %s",a[no-1]);
}
}
else
printf("\tEnter the small number");
getch();
}
<STRING.H>FUNCTION PROGRAMS…
46. STRUPR (USE FOR CHANGE CASE OF CHARACTER a->A)
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
char m1[20],m2[10];
clrscr();
printf("\nEnter The String to abc->ABC");
scanf("%s",&m2);
printf("\nThe string is %s\t",strupr(m2));
getch();
}
47. STRLWR (USE FOR CHANGE CASE OF CHARACTER A->a)
#include<conio.h>
#include<stdio.h>
MSB PRODUCTION 28
Mo. No. - 9922108881
Created By Mukesh Badgujar

#include<string.h>
void main()
{
char m1[20],m2[10];
clrscr();
printf("Enter The String");
scanf("%s",&m1);
printf("The string is %s\t",strlwr(m1));

printf("Enter The String");


scanf("%s",&m2);
printf("The string is %s\t",strupr(m2));
getch();
}
48. STRREV(TO REVERSE THE STRING ABC->CBA)
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
char m1[20],m2[10];
clrscr();
printf("Enter The String to reverse it");
scanf("%s",&m1);
printf("The string is %s\t",strrev(m1));
getch();
}
49. STRLEN(TO FIND THE NUMBER OF CHARACTER IN STRING)
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
char m1[20];
int a;
clrscr();
printf("Enter The String");
gets(m1);
a=strlen(m1);
printf("The string is %d",a);
getch();
}
50. STRCPY(TO COPPY SECOND STRING TO FIRST STRING)
#include<conio.h>
#include<stdio.h>

MSB PRODUCTION 29
Mo. No. - 9922108881
Created By Mukesh Badgujar

#include<string.h>
void main()
{
char m1[20]="msb";
char m2[20]="qwe";
int a;
strcpy(m1,m2);
clrscr();
strcpy(m1,m2);
printf("The string is %s",m1);
getch();
}
51. STRCMP(IT COMPARE TWO STRING AND PRING RESULT AS + OR - NUMBER)
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
char m1[20]="abcdefghi";
char m2[20]="ABCDEFGHI";
int a;
strcmp(m1,m2);
clrscr();
printf("The string is %d",strcmp(m1,m2));
getch();
}
52. STRCAT(TO JOINT 1ST AND 2ND STRING)
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
char m1[20]="msb";
char m2[20]="qwe";
int a;
strcat(m1,m2);
clrscr();
printf("To joint the string is %s",m1);
getch();
}
53. ALL SRT….. FUNCTIONS COMBINE
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()

MSB PRODUCTION 30
Mo. No. - 9922108881
Created By Mukesh Badgujar

{
char m1[20],m2[20];
int a;
clrscr();
printf("\nEnter The String to REV");
scanf("%s",&m1);
printf("\nThe string is %s\t",strrev(m1));

printf("\nEnter The String to UPP");


scanf("%s",&m2);
printf("\nThe string is %s\t",strupr(m2));

printf("\nEnter The String to LWR");


scanf("%s",&m1);
printf("\nThe string is %s\t",strlwr(m1));

printf("\nEnter The String to find LENGTH");


scanf("%s",&m1);
a=strlen(m1);
printf("\nThe string is %d",a);

printf("\nEnter The String CPY");


scanf("%s",&m1);
printf("\nEnter The String CPY");//these string coppy to first string
scanf("%s",&m2);
strcpy(m1,m2);
clrscr();
strcpy(m1,m2);
printf("\nThe string is %s",m1);

printf("\nEnter The String Compair");//it CMP the case character.


scanf("%s",&m1);
printf("\nEnter The String Compair");
scanf("%s",&m2);
strcmp(m1,m2);
printf("\nThe string is %d",strcmp(m1,m2));

printf("\nEnter The String CAT");//it joint's second string.


scanf("%s",&m1);
printf("\nEnter The String CAT");
scanf("%s",&m2);
strcat(m1,m2);
printf("\nThe string is %s",m1);
getch();
}

MSB PRODUCTION 31
Mo. No. - 9922108881

You might also like