Pps Sess2
Pps Sess2
23. WAP to find the minimum and maximum element of the array.
CODE:
#include <stdio.h>
#include<conio.h>
int main()
{
int a[10], n, i, max, min;
clrscr();
OUTPUT:
SHRUTI PRASAD 22CE055
24.WAP to search an element in an array using Linear Search.
CODE:
#include <stdio.h>
#include<conio.h>
void main()
{
int i, x, n, flag=0, a[10];
clrscr();
OUTPUT:
SHRUTI PRASAD 22CE055
26.WAP to add and multiply two matrices of order nxn.
CODE:
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, k, n, a[10][10], b[10][10], sum[10][10], prod[10][10];
clrscr();
printf("enter order of matrices: ");
scanf("%d", &n);
CODE:
#include<stdio.h>
#include<conio.h>
int main()
{
int ar[100],n, low, high, mid, item;
clrscr();
printf("Enter the no of elements in array--");
scanf("%d",&n);
printf("Enter elements of array:\n");
for(int i=0; i<n; i++)
{
printf ("enter the %d element: " i+1);
scanf ("%d",&ar[i]);
}
printf ("Enter the elements to be searched: ");
scanf (“%d",&item);
low=0;
high=n-1;
mid=(low+high)/2;
while(low<=high)
if(ar[mid]==item)
{
printf("%d element is present at %d",item, mid+1);
break;
}
else if (ar[mid]<item)
{
low=mid+1;
mid=(low+high)/2;
}
else
{
high=mid-1;
mid=(low+high)/2;
}
getch();
}
OUTPUT:
SHRUTI PRASAD 22CE055
27. WAP that finds the sum of diagonal elements of a mxn matrix.
CODE:
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, r, c, sum, arr[10][10];
clrscr();
printf("enter no. of rows and columns of matrix: ");
scanf("%d %d", &r, &c);
OUTPUT:
SHRUTI PRASAD 22CE055
25. WAP to sort the elements of the array in ascending order using Bubble Sort technique.
CODE:
#include<stdio.h>
#include<conio.h>
int main()
{
int a[10], n, temp;
clrscr();
printf("Enter the no of elements in array--");
scanf("%d",&n);
printf("Enter elements of array\n");
for(int i=0;i<n;i++)
{
printf("enter the %d element: " i+1);
scanf("%d", &a[i]);
}
printf("\n");
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-1;j++)
{
if(a[j+1]<a[j])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("sorted array:\n");
for(int i=0;i<n;i++)
{
printf("%d ",a[i]);
}
getch();
}
OUTPUT: