Tuesday, November 29, 2022

Calculate time for a Program

 #include<conio.h>

#include<stdio.h>

#include<time.h>

#include<dos.h>

void main()

{


int a[10][10],b[10][10],c[10][10],i,j,r,l;

time_t start, end;

double tot_time;

clrscr();

start=clock();

printf("enter no. of rows=");

scanf("%d",&r);

printf("enter no. of columns=");

scanf("%d",&l);

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

for(j=0;j<l;j++)

scanf("%d",&a[i][j]);

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

for(j=0;j<l;j++)

scanf("%d",&b[i][j]);

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

for(j=0;j<l;j++)

c[i][j]=a[i][j]+b[i][j];

printf("%d", c[i][j]);

delay(50):

printf("\n");

end=clock();

tot_time=((double) (end-start))/CLOCKS_PER_SEC;

printf("'In time=%f",tot_time);

getch();

}


Insertion Sort C Program

 /* Insertion Sort *

#include<stdio.h>

#include<conio.h>


void insertion(int x[],int n)

{

int i,j,temp;

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

{

temp=x[i];


for(j=i-1;j>=0;j--)

{

if(temp<x[j])

x[j+1]=x[j];

else

break;

}


x[j+1]=temp;

}}

void main()

{

int x[10],n,i;

clrscr();

printf("Enter the number of elements: ");

scanf("%d",&n);

printf("\nEnter the elements: \n");

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

scanf("%d",&x[i]);

insertion(x,n);

printf("\nThe sorted output:\n");

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

printf("\n%d",x[i]);


getch();

}