CS Abstract

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 61

 Experiment Number: 01

 Name of the Program: Write a program to print “Hello World!!!”

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
printf("Hello World !!!");
getch();
return 0;
}

 Output:
 Experiment Number: 02

 Name of the Program: Write a program to make addition of two numbers.

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
inta,b,c;
printf("Enter the two value : ");
scanf("%d%d",&a,&b);
c=a+b;
printf("Addition of numbers is : %d",c);
getch();
return 0;
}

 Output:
 Experiment Number: 03

 Name of the Program: Write a program to calculate the area of a rectangle

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
int length, breadth, area;
printf("\nEnter the Length of Rectangle : ");
scanf("%d", &length);
printf("\nEnter the Breadth of Rectangle : ");
scanf("%d", &breadth);
area = length * breadth;
printf("\nArea of Rectangle : %d", area);
getch();
return (0);
}

 Output:
 Experiment Number: 04

 Name of the Program: Write a program to calculate the equation


((a+b)*(c+d))/e

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
printf("Equation for ((a+b)*(c+d))/e");
printf("\n**************************");
float a,b,c,d,e,x;
printf("Enter the values of a : ");
scanf("%f",&a);
printf("Enter the values of b : ");
scanf("%f",&b);
printf("Enter the values of c : ");
scanf("%f",&c);
printf("Enter the values of d : ");
scanf("%f",&d);
printf("Enter the values of e : ");
scanf("%f",&e);
x=((a+b)*(c+d))/e;
printf("The value is =%f",x);
getch();
return 0;
}

 Output:
 Experiment Number: 05

 Name of the Program: Write a program to calculate the area of a circle &
perimeter where radius will be user input

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
float a,x,p;
printf("Enter the radius of the circle : ");
scanf("%f",&a);
x= 3.1416*a*a;
printf("The Area of the circle is : %f",x);
printf("\n");
p=2*3.1416*a;
printf("The Perimeter of the circle is : %f",p);
getch();
return 0;
}

 Output:
 Experiment Number: 06

 Name of the Program: Write a program to convert Celsius to Fahrenheit

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
float fahrenheit, celsius;
printf("Enter celsius : ");
scanf("%f",&celsius);
fahrenheit = (celsius * 9 / 5) + 32;
printf("Fahrenheit: %f \n", fahrenheit);
getch();
return 0;
}

 Output:
 Experiment Number: 07

 Name of the Program: Write a program to convert Fahrenheit to Celsius

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
float fahrenheit, celsius;
printf("Enter Fahrenheit: ");
scanf("%f",&fahrenheit);
celsius = (fahrenheit - 32)*5/9;
printf("Celsius: %f \n", celsius);
getch();
return 0;
}

 Output:
 Experiment Number: 08

 Name of the Program: Write a program to calculate the equation


X = a^6 +ab^2 + b^6

 Coding:

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
printf("Equation for X = a^6 +ab^2 + b^6 ");
printf("\n**************************\n\n");
float a,b,x;
printf("Enter the value of a : ");
scanf("%f",&a);
printf("Enter the value of b : ");
scanf("%f",&b);
x=pow(a,6)+(a*pow(b,2))+pow(b,6);
printf("The Calculated value of X is : %f",x);
getch();
return 0;
}
 Output:
 Experiment Number: 09

 Name of the Program: Write a program to calculate the equation


X = a^5

 Coding:

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
printf("Equation for X = a^5 ");
printf("\n**************************\n\n");
inta,x;
printf("Enter the value of a : ");
scanf("%d",&a);
x=pow(a,5);
printf("%d",x);
getch();
return 0;
}

 Output:
 Experiment Number: 10

 Name of the Program: Write a program to calculate the equation


X = ((a+b)*(c+d))/(p+q)

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
printf("Equation for X = ((a+b)*(c+d))/(p+q) ");
printf("\n**************************\n\n");
float a,b,c,d,p,q,x;
printf("Enter the value of a : ");
scanf("%f",&a);
printf("Enter the value of b : ");
scanf("%f",&b);
printf("Enter the value of c : ");
scanf("%f",&c);
printf("Enter the value of d : ");
scanf("%f",&d);
printf("Enter the value of p : ");
scanf("%f",&p);
printf("Enter the value of q : ");
scanf("%f",&q);
x=((a+b)*(c+d))/(p+q);
printf("The Final value of the Equation is : %f",x);
getch();
return 0;
}
 Output:
 Experiment Number: 11

 Name of the Program: Write a program to calculate the area of a right angled
Triangle

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
float a,b,X;
printf("Enter the value of a : ");
scanf("%f",&a);
printf("Enter the value of b : ");
scanf("%f",&b);
X=(a*b)/2;
printf("The Area of the Right angled triangle is : %f",X);
getch();
return 0;
}

 Output:
 Experiment Number: 12

 Name of the Program: Write a program to calculate the area of a Trapizium

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
float a,b,h,x;
printf("Enter the value of a : ");
scanf("%f",&a);
printf("Enter the value of b : ");
scanf("%f",&b);
printf("Enter the value of h : ");
scanf("%f",&h);
x=((a+b)/2)*h;
printf("The Are of the Trapizium is : %f",x);
getch();
return 0;
}

 Output:
 Experiment Number: 13

 Name of the Program: Write a program to swap two numbers

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
float a,b;
printf("Enter the value of a : ");
scanf("%f",&a);
printf("Enter the value of b : ");
scanf("%f",&b);
printf("The value of a : %f",b);
printf("\nThe value of b : %f",a);
getch();
return 0;
}

 Output:
 Experiment Number: 14

 Name of the Program: Write a program to solve a quadratic equation

 Coding:

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
printf("Quadratic Equation\n");
printf("********************\n\n");
int a,b,c,d,x1,x2;
printf("ax^2+bx+c :");
printf("\n\n");
printf("Enter value of a : ");
scanf("%d",&a);
printf("Enter value of b : ");
scanf("%d",&b);
printf("Enter value of c : ");
scanf("%d",&c);
printf("\n");
printf("Equation : %dx^2+%dx+%d",a,b,c);
printf("\n\n");
d = sqrt((b*b)-(4*a*c));
if(d>0)
{
x1 = (-b+d)/(2*a);
x2 = (-b-d)/(2*a);
printf("Values of x : %d,%d ",x1,x2);
}
else if(d<0)
{
printf("Roots are Imaginary");
}
else if(d==0)
{
x1 = (-b+d)/(2*a);
x2 = (-b-d)/(2*a);
printf("Values of x : %d,%d ",x1,x2);
}
getch();
return 0;
}

 Output:
 Experiment Number: 15

 Name of the Program: Write a program to draw matrix form using ‘*’

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
printf("Design\n");
printf("*******\n\n");
intn,i,j;
printf("Enter Number of Terms :");
scanf("%d",&n);
printf("\n");
for(i=1;i<=n;i=i+1)
{
for(j=1;j<=n;j=j+1)
{
printf(" * ");
}
printf("\n");
}
getch();
return 0;
}

 Output:
 Experiment Number: 16

 Name of the Program: Write a program of a Fibonacci series

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
printf("Fibonacci Series\n");
printf("*****************\n\n");
int a=0,b=1,n,s,i;
printf("Enter Number of Terms : ");
scanf("%d",&n);
printf("\n");
printf("%d",a);
printf("\n");
printf("%d",b);
printf("\n");
for(i=3;i<=n;++i)
{
s = a+b;
printf("%d",s);
printf("\n");
a = b;
b = s;
}
getch();
return 0;
}
 Output:
 Experiment Number: 17

 Name of the Program: Write a program to draw L shape using ‘*’

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
inti=0;
for(i=0;i<=4;i++)
{
printf("*");
printf("\n");
}
for(i=0;i<1;i++)
{
printf("* * * * * *");
printf("\n");
}
getch();
return 0;
}

 Output:
 Experiment Number: 18

 Name of the Program: Write a program to draw a 4x4 matrix

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
inti=0;
for(i=0;i<=3;i++)
{
printf("* * * *");
printf("\n");

}
getch();
return 0;
}

 Output:
 Experiment Number: 19

 Name of the Program: Write a program of a Fibonacci series

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
inti=0;
for(i=0;i<=9;i++)
{
printf("*");
printf("\n");

}
getch();
return 0;
}

 Output:
 Experiment Number: 20

 Name of the Program: Write a program to find a leap year

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
int year;
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0)
{
if ( year%400 == 0)
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
}
else
printf("%d is a leap year.", year );
}
else
printf("%d is not a leap year.", year);
getch();
return 0;
}
 Output:
 Experiment Number: 21

 Name of the Program: Write a program to check given three points fall on one
straight line

 Coding:

#include <stdio.h>
#include <conio.h>
int main()
{
int x1,y1,x2,y2,x3,y3,x4,y4,slope1,slope2;
printf("\n Enter 1st co-ordinate (x1,y1) : ");
scanf("\n %d%d",&x1,&y1);
printf("\n Enter 2nd co-ordinate (x2,y2) : ");
scanf("\n %d%d",&x2,&y2);
printf("\n Enter 3rd co-ordinate (x3,y3) : ");
scanf("\n %d%d",&x3,&y3);
slope1=(y2-y1)/(x2-x1);
slope2=(y3-y2)/(x3-x2);
if(slope1==slope2)
{
printf("\n Three points fall on the same line");
}
else
{
printf("\nThree points doesn't fall on the same line");
}
getch();
return 0;
}

 Output:
 Experiment Number: 22

 Name of the Program: Write a program to find out a given no of 3 digit and
make reverse of it and determine the original & reverse no are equal or not

 Coding:

#include <stdio.h>
#include<conio.h>
int main()
{
int n, reversedInteger = 0, remainder, originalInteger;
printf("Enter an integer: ");
scanf("%d", &n);
originalInteger = n;
while( n!=0 )
{
remainder = n%10;
reversedInteger = reversedInteger*10 + remainder;
n /= 10;
}
if (originalInteger == reversedInteger)
printf("%d is a palindrome.", originalInteger);
else
printf("%d is not a palindrome.", originalInteger);
return 0;
}

 Output:
 Experiment Number: 23

 Name of the Program: Write a program to make a reverse of a number

 Coding:

#include<stdio.h>
#include<conio.h>
int main ()
{
int n, reverse = 0;
printf("Enter a number : ");
scanf("%d", &n);
while (n != 0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
printf("In Reverse : %d",reverse);
getch();
return 0;
}

 Output:
 Experiment Number: 24

 Name of the Program: Write a program to find odd or even number

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
int n;
printf("Enter an integer : ");
scanf("%d", &n);
if(n % 2 == 0)
printf("%d is even.", n);
else
printf("%d is odd.", n);
getch();
return 0;
}

 Output:
 Experiment Number: 25

 Name of the Program: Write a program to add numbers using loop

 Coding:

#include <stdio.h>
#include <conio.h>
int main()
{
inti, num, sum = 0,r;
printf("Enter an integer number: ");
scanf ("%d", &num);
while(num>0)
{
r = num%10;
sum = sum + r;
num = num/10;
}
printf ("Sum of numbers = %d",sum);
getch();
return 0;
}

 Output:
 Experiment Number: 26

 Name of the Program: Write a program to find prime numbers between 1


to 50

 Coding:

#include <stdio.h>
#include <conio.h>
int main()
{
for(inti=2;i<50;i++)
{
for(int j=2;j<i;j++)
{
if(i%j==0)
break;
else if(i==j+1)
printf("%d\n",i);
}
}
getch();
return 0;
}

 Output:
 Experiment Number: 27

 Name of the Program: Write a program to calculate the gross salary maintain
conditions . If basic salary in 20,000 then

20000– DA – 80% of BP
HRA – 10% of BP
GP – 6000
25000– DA – 90% of BP
HRA – 10% of BP
GP - 6000
30000– DA – 100% of BP
HRA – 10% of BP
GP - 6000

 Coding:

#include <stdio.h>
#include <conio.h>
int main()
{
int BP;
printf("Enter Basic Pay : ");
scanf("%d",&BP);
printf("\n");
float DA,HRA,GP,GS;
if (BP==20000)
{
DA=(80*BP)/100;
HRA=(10*BP)/100;
GP= 6000;
GS= DA + HRA +GP +BP;
printf("Gross salary : %f",GS);
}
else if(BP==25000)
{
DA=(90*BP)/100;
HRA=(10*BP/100);
GP= 7000;
GS= DA + HRA + GP + BP;
printf("Gross Salary :%f",GS);
}
else if (BP==30000)
{
DA= BP;
HRA= (10*BP)/100;
GP= 8000;
GS= DA + HRA + GP + BP;
printf("Gross Salary :%f",GS);
}
else
printf("Wrong Input");
getch();
return 0;
}

 Output:
 Experiment Number: 28

 Name of the Program: Consider a mobile billing system where price of a mobile
is rs 10,000 and GST is 18% and govt CESS Tax 0.5%. Write a program such
that the shop owner can make a profit of the basic price 12% of the gross of the
product

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
float BP, GST, CESS, PROFIT, GROSS, TOTAL;
printf("\n Enter the Basic Price : ");
scanf("%f",&BP);
GST=(BP*0.18);
CESS=(BP*0.005);
GROSS=(BP+GST+CESS);
PROFIT=(GROSS*0.12);
TOTAL=(GROSS + PROFIT);
printf("\n Total Price : %f",TOTAL);
getch();
return 0;
}

 Output:
 Experiment Number: 29

 Name of the Program: Write a program to find out the arrange grade of a std.
assume the following condition
1. There are four subjects – Phy, Che, Math, Cs
2. The passing marks for the std. is 40%
3. If the std. gets > 90%, grade will be “O”
4. If the std. gets > 80%, grade will be “E”
5. If the std. gets > 70%, grade will be “A”
6. If the std. gets > 60%, grade will be “B”
7. If the std. gets > 50%, grade will be “C”
8. If the std. gets > 40%, grade will be “D”

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
inta,b,c,d;
float A;
printf(" Enter the marks of Phy : ");
scanf("%d",&a);
printf(" Enter the marks of Che : ");
scanf("%d",&b);
printf(" Enter the marks of Math : ");
scanf("%d",&c);
printf(" Enter the marks of CS : ");
scanf("%d",&d);
A=(a+b+c+d)/4;
if(A>90&& A<=100)
{
printf("Grade O ");
}
else if (A>80 && A<=89)
{
printf("Grade E ");
}
else if (A>70 && A<=79)
{
printf("Grade A ");
}
else if (A>60 && A<=69)
{
printf("Grade B ");
}
else if (A>50 && A<=59)
{
printf("Grade C ");
}
else if (A>40 && A<=49)
{
printf("Grade D ");
}
else
{
printf("FAIL");
}
getch();
return 0;
}

 Output:
 Experiment Number: 30

 Name of the Program: Write a program to find odd or even number

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
int n;
printf("Enter an integer : ");
scanf("%d", &n);
if(n % 2 == 0)
printf("%d is even.", n);
else
printf("%d is odd.", n);
getch();
return 0;
}

 Output:
 Experiment Number: 31

 Name of the Program: Write a program to draw a pattern using loop

*
**
***
****
*****

 Coding:

#include <stdio.h>
#include<conio.h>
int main()
{
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=1; i<=rows; ++i)
{
for(j=1; j<=i; ++j)
{
printf("* ");
}
printf("\n");
}
return 0;
}

 Output:
 Experiment Number: 32

 Name of the Program: Write a program to draw a pattern using loop

1
12
123
1234
12345

 Coding:

#include <stdio.h>
#include<conio.h>
int main()
{
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=1; i<=rows; ++i)
{
for(j=1; j<=i; ++j)
{
printf("%d ",j);
}
printf("\n");
}
return 0;
}
 Output:
 Experiment Number: 33

 Name of the Program: Write a program to draw a pattern using loop

*****
****
***
**
*

 Coding:

#include <stdio.h>
#include<conio.h>
int main()
{
int i, j, rows;

printf("Enter number of rows: ");


scanf("%d",&rows);

for(i=rows; i>=1; --i)


{
for(j=1; j<=i; ++j)
{
printf("* ");
}
printf("\n");
}

return 0;
}
 Output:
 Experiment Number: 34

 Name of the Program: Write a program to draw a pattern using loop

*
***
*****
*******
*********

 Coding:

#include <stdio.h>
#include<conio.h>
int main()
{
int i, space, rows, k=0;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=1; i<=rows; ++i, k=0)
{
for(space=1; space<=rows-i; ++space)
{
printf(" ");
}
while(k != 2*i-1)
{
printf("* ");
++k;
}
printf("\n");
}
return 0;
}
 Output:
 Experiment Number: 35

 Name of the Program: Write a program to draw a pattern using loop

*********
*******
*****
***
*
 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
int rows, i, j, space;
printf("Enter number of rows: ");
scanf("%d",&rows);

for(i=rows; i>=1; --i)


{
for(space=0; space < rows-i; ++space)
printf(" ");

for(j=i; j <= 2*i-1; ++j)


printf("* ");

for(j=0; j < i-1; ++j)


printf("* ");

printf("\n");
}

return 0;
}
 Output:
 Experiment Number: 36

 Name of the Program: Write a program to draw a pattern using loop

*****
*****
*****
*****
*****

 Coding:

#include <stdio.h>
#include <conio.h>
int main()
{
int i,j;
for (i=0; i<5; i++)
{
for (j=0; j<5; j++)
{
printf(" * ");
}
printf("\n");
}
getch();
}
 Output:
 Experiment Number: 37

 Name of the Program :Write a program to draw a pattern using loop

*
**
***
****
*****
 Coding:

#include <stdio.h>
#include<conio.h>
int main()
{
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d", &rows);
for(i=1; i<=rows; i++)
{
for(j=i; j<rows; j++)
{
printf(" ");
}
for(j=1; j<=i; j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
 Output:
 Experiment Number: 38

 Name of the Program: Write a program to draw a pattern using loop

*****
****
***
**
*
 Coding:

#include <stdio.h>
#include<conio.h>
int main()
{
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d", &rows);
for(i=1; i<=rows; i++)
{
for(j=1; j<i; j++)
{
printf(" ");
}
for(j=i; j<=rows; j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
 Output:
 Experiment Number: 39

 Name of the Program: Write a program to draw a pattern using loop

*
***
*****
*******
*********
*******
*****
***
*
 Coding:

#include <stdio.h>
#include<conio.h>
int main()
{
int n, c, k, space = 1;
printf("Enter number of rows\n");
scanf("%d", &n);
space = n - 1;
for (k = 1; k <= n; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space--;
for (c = 1; c <= 2*k-1; c++)
printf("*");
printf("\n");
}
space = 1;
for (k = 1; k <= n - 1; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space++;
for (c = 1 ; c <= 2*(n-k)-1; c++)
printf("*");
printf("\n");
}
return 0; }
 Output:
 Experiment Number: 40

 Name of the Program: Write a program to draw a pattern using loop

*****
*****
*****
*****
*****
 Coding:

#include <stdio.h>
#include<conio.h>
int main()
{
int i, j, rows;
printf("Enter rows: ");
scanf("%d", &rows);
for(i=1; i<=rows; i++)
{
for(j=1; j<=rows - i; j++)
{
printf(" ");
}
for(j=1; j<=rows; j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
 Output:
 Experiment Number: 41

 Name of the Program: Write a program to declare characters using array

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
int i, a[10],n;
printf("Enter the no of elements :");
scanf("%d",&n);
printf("Enter the elements :");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("The entered values are :\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
getch();
return 0;
}
 Output:
 Experiment Number: 42

 Name of the Program: Write a program to show the largest number

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
int i, a[10],n,L,l2;
printf("Enter the no of elements :");
scanf("%d",&n);
printf("Enter the elements :");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
L = a[0];

for(i=0;i<n;i++)
{
if (L < a[i])
L = a[i];
}
printf("\n largest element present in the given array is : %d", L);
L = a[1];
getch();
return 0;
}

 Output:
 Experiment Number: 43

 Name of the Program: Write a program to find the 2nd smallest number

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
int i, a[10],n,S,S_a;
printf("Enter the no of elements :");
scanf("%d",&n);
printf("Enter the elements :",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
S = S_a =a[1];

for(i=1;i<n;i++)
{
if(S>a[i])
{
S_a = S;
S = a[i];
}
else if(S_a>a[i] && a[i]!= S)
{
S_a=a[i];
}

}
printf("\n The Second Smallest Element in the given Array: %d", S_a);
getch();
return 0;
}
 Output:
 Experiment Number: 44

 Name of the Program: Write a program to insert an element in desired position

 Coding:

#include <stdio.h>
#include<conio.h>
int main()
{
int array[100], position, c, n, value;

printf("Enter number of elements in array\n");


scanf("%d", &n);

printf("Enter %d elements\n", n);

for (c = 0; c < n; c++)


scanf("%d", &array[c]);

printf("Enter the location where you wish to insert an element\n");


scanf("%d", &position);

printf("Enter the value to insert\n");


scanf("%d", &value);

for (c = n - 1; c >=position-1; c--)


array[c+1] = array[c];
array[position-1] = value;

printf("Resultant array is\n");

for (c = 0; c <=n; c++)


printf("%d\n", array[c]);
return 0;
}
 Output:
 Experiment Number: 45

 Name of the Program: Write a program to delete characters from desired position

 Coding:

#include <stdio.h>
#include<conio.h>
int main()
{
int array[100], position, c, n;

printf("Enter number of elements in array\n");


scanf("%d", &n);

printf("Enter %d elements\n", n);

for (c = 0; c < n; c++)


scanf("%d", &array[c]);

printf("Enter the location where you wish to delete element\n");


scanf("%d", &position);

if (position >= n+1)


printf("Deletion not possible.\n");
else
{
for (c = position - 1; c < n - 1; c++)
array[c+1] = array[c];

printf("Resultant array:\n");

for (c = 0; c < n - 1; c++)


printf("%d\n", array[c]);
}

return 0;
}
 Output:
 Experiment Number: 46

 Name of the Program: Write a program to reverse the user given characters

 Coding:

#include <stdio.h>
#include <conio.h>
int main()
{
int a[100], n, c, t, end;
printf("Enter the no of elements :");
scanf("%d",&n);
printf("Enter the elements :",n);
for(c=0;c<n;c++)
end = n - 1;

for (c = 0; c < n; c++)


{
scanf("%d", &a[c]);
}

for (c = 0; c < n/2; c++)


{
t = a[c];
a[c] = a[end];
a[end] = t;

end--;
}

printf("Reversed array elements are:\n");

for (c = 0; c < n; c++)


{
printf("%d\n", a[c]);
}

return 0;
}
 Output:
 Experiment Number: 47

 Name of the Program: Write a program to draw matrix in 2D array

 Coding:

#include<stdio.h>
#include<conio.h>
int main()
{
int disp[2][3];
int i, j;
for(i=0; i<2; i++)
{
for(j=0;j<3;j++)
{
printf("Enter value for disp[%d][%d]:", i, j);
scanf("%d", &disp[i][j]);
}
}
printf("Two Dimensional array elements:\n");
for(i=0; i<2; i++)
{
for(j=0;j<3;j++)
{
printf("%d ", disp[i][j]);
if(j==2){
printf("\n");
}
}
}
return 0;
}
 Output:
 Experiment Number: 48

 Name of the Program: Write a program to add two matrix in 2D array

 Coding:

#include <stdio.h>
#include <conio.h>
int main()
{
int m, n, i, d, first[10][10], second[10][10], sum[10][10];

printf("Enter the number of rows and columns of matrix\n");


scanf("%d%d", &m, &n);
printf("Enter the elements of first matrix\n");

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


for (d = 0; d < n; d++)
scanf("%d", &first[i][d]);

printf("Enter the elements of second matrix\n");

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


for (d = 0 ; d < n; d++)
scanf("%d", &second[i][d]);

printf("Sum of entered matrices:-\n");

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


{
for (d = 0 ; d < n; d++)
{
sum[i][d] = first[i][d] + second[i][d];
printf("%d\t", sum[i][d]);
}
printf("\n");
}

getch();
return 0;
}
 Output:
 Experiment Number: 49

 Name of the Program: Write a program to multiply two matrix in 2D array

 Coding:

#include <stdio.h>
#include <conio.h>
int main()
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];

printf("Enter number of rows and columns of first matrix\n");


scanf("%d%d", &m, &n);
printf("Enter elements of first matrix\n");

for (c = 0; c < m; c++)


for (d = 0; d < n; d++)
scanf("%d", &first[c][d]);

printf("Enter number of rows and columns of second matrix\n");


scanf("%d%d", &p, &q);

if (n != p)
printf("The matrices can't be multiplied with each other.\n");
else
{
printf("Enter elements of second matrix\n");

for (c = 0; c < p; c++)


for (d = 0; d < q; d++)
scanf("%d", &second[c][d]);

for (c = 0; c < m; c++)


{
for (d = 0; d < q; d++)
{
for (k = 0; k < p; k++)
{
sum = sum + first[c][k]*second[k][d];
}
multiply[c][d] = sum;
sum = 0;
}
}

printf("Product of the matrices:\n");

for (c = 0; c < m; c++)


{
for (d = 0; d < q; d++)
printf("%d\t", multiply[c][d]);

printf("\n");
}
}

return 0;
}
 Output:

You might also like