Matrix Addition in C

Here you will find program for matrix addition in C. Two matrix can be added only when number of rows and columns of first matrix is equal to number of rows of columns of second matrix. Matrix Addition in C #include<stdio.h> int main() { int a[5][5],b[5][5],c[5][5],i,j,m,n; printf(“How many rows and columns?”); scanf(“%d%d”,&m,&n); printf(“\nEnter first matrix:\n”); …

Matrix Addition in C Read More »

Bubble Sort in C

Here you will learn about program for bubble sort in C. Bubble sort is a simple sorting algorithm in which each element is compared with adjacent element and swapped if their position is incorrect. It is named as bubble sort because same as like bubbles the lighter elements come up and heavier elements settle down. …

Bubble Sort in C Read More »

Simple program to create a moving car in graphics

#include<graphics.h> #include<conio.h> #include<dos.h> void main() { int gdriver=DETECT,gmode,i=0,j=0; initgraph(&gdriver,&gmode,”c:\turboc3\bgi”); for(i;i<420;++i) { line(0,245,650,245); line(0+i,200,210+i,200); line(50+i,200,70+i,170); line(70+i,170,140+i,170); line(140+i,170,160+i,200); line(85+i,170,85+i,200); line(125+i,170,125+i,200); line(0+i,200,0+i,230); line(210+i,200,210+i,230); line(0+i,230,50+i,230); circle(65+i,230,15); line(80+i,230,130+i,230); circle(145+i,230,15); line(210+i,230,160+i,230); pieslice(65+i,230,359-j,360-j,15); pieslice(65+i,230,179-j,180-j,15); pieslice(65+i,230,89-j,90-j,15); pieslice(65+i,230,269-j,270-j,15); pieslice(145+i,230,359-j,360-j,15); pieslice(145+i,230,179-j,180-j,15); pieslice(145+i,230,89-j,90-j,15); pieslice(145+i,230,269-j,270-j,15); if(j==179) j=0; ++j; delay(30); cleardevice(); } closegraph(); }

C Program to Find Sum of Diagonals of Matrix

Here is the C program to find sum of diagonal of a square matrix. #include<stdio.h> int main() { int i,j,n,d1=0,d2=0,a[5][5]; printf(“Enter size of square matrix:”); scanf(“%d”,&n); printf(“Enter Elements of matrix:\n”); for(i=0;i<n;++i) for(j=0;j<n;++j) { scanf(“%d”,&a[i][j]); if(i==j) d1+=a[i][j]; if((i+j)==(n-1)) d2+=a[i][j]; } printf(“\nFirst Diagonal Sum=%d”,d1); printf(“\nSecond Diagonal Sum=%d”,d2); return 0; }   Output Enter size of square matrix:4 …

C Program to Find Sum of Diagonals of Matrix Read More »