Top Banner
Program 1 Write a program to perform insertion sort. #include<stdio.h> #include<conio.h> void main() { clrscr(); int i,t,a[100],d,n; printf("Enter The No. Of Elements\n"); scanf("%d",&n); printf("Enter %d Integers\n",n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=1;i<=n-1;i++) { d=i; while(d>0&&a[d]<a[d-1]) { t=a[d]; a[d]=a[d-1]; a[d-1]=t; d--; } } printf("Sorted List in Ascending Order is:\n"); for(i=0;i<=n-1;i++) { printf("%d\t",a[i]); } getch(); }
30

DAA Lab File C Programs

Jul 13, 2015

Download

Education

Kandarp Tiwari
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

Program 1

Write a program to perform insertion sort.

#include#includevoid main(){clrscr();int i,t,a[100],d,n;printf("Enter The No. Of Elements\n");scanf("%d",&n);printf("Enter %d Integers\n",n);for(i=0;i