C program to sort a list of numbers using Insertion Sort

/*Insertion sort in ascending order*/ #include<conio.h> #include<stdio.h> int main() { int n, array[100], c,d,t; printf(“Enter number of elements\n”); scanf(“%d”,&n); printf(“Enter %d integers\n”,n); for(c=0;c<n;c++) scanf(“%d”, &array[c]); for(c=1;c<=n-1;c++) { d=c; while(d>0 && array[d]<array[d-1]) { t=array[d]; array[d]=array[d-1]; array[d-1]=t; d–; } } printf(“Sorted list in ascending order:\n”); for(c=0;c<n;c++) printf(“%d\n”, array[c]); return 0; }

Continue Reading

C program to sort a list of numbers using Bubble Sort

#include<conio.h> #include<stdio.h> int main() { int array[100], n, c, d, swap; printf(“Enter number of elements\n”); scanf(“%d”, &n); printf(“Enter %d integers \n”,n); for(c=0;c<n;c++) { for(d=0;d<(n-c-1);d++) { if(array[d]>array[d+1]) { swap=array[d]; array[d]=array[d+1]; array[d+1]=swap; } } } printf(“Sorted list in ascending order:\n”); for(c=0;c<n;c++) printf(“%d\n”, array[c]); return 0; }

Continue Reading

C program to sort an array using Selection Sort

#include<conio.h> #include<stdio.h> int main() { int array[100],n,c,d,position,swap; printf(“Enter number of elements\n”); scanf(“%d”, &n); printf(“Enter %d integers\n”,n); for(c=0;c<n;c++) scanf(“%d”, &array[c]); for(c=0;c<(n-1);c++) { position=c; for(d=c+1;d<n;d++) { if(array[position]>array[d]) position=d; } if(position!=c) { swap=array[c]; array[c]=array[position]; array[position]=swap; } } printf(“Sorted list in ascending order:\n”); for(c=0;c<n;c++) printf(“%d\n”, array[c]); return 0; }

Continue Reading

C program to add, subtract and multiply two complex numbers using structure

#include<conio.h> #include<stdio.h> #include<stdio.h> struct complex { int real, img; }; int main() { int choice; struct complex a,b,c; while(1) { printf(“Press 1 to add two complex numbers.\n”); printf(“Press 2 to subtract two complex numbers.\n”); printf(“Press 3 to multiply two complex numbers.\n”); printf(“Press 4 to exit.\n”); printf(“Enter your choice.\n”); scanf(“%d”,&choice); if(choice==4) exit(0); if(choice>=1 && choice<=3) { […]

Continue Reading

C program to multiply and subtract two matrices.

#include<conio.h> #include<stdio.h> int main() { int m,n,p,q,c,d,k,sum=0; int first[10][10], second[10][10], multiply[10][10], difference[10][10]; printf(“Enter the number of rows and column of first matrix \n”); scanf(“%d%d”, &m,&n); printf(“Enter the elements of first matrix\n”); for(c=0;c<m;c++) for(d=0;d<n;d++) scanf(“%d” &first[c][d]); printf(“Enter the number of rows and column of second matrix\n”); scanf(“%d%d”, &p,&q); if(n!=p) { printf(“Matrices with entered orders cannot be […]

Continue Reading