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 »

C Program to Insert an Element in an Array

Here is the simple C program to insert an element in a one dimensional array. The array should be in ascending order. #include<stdio.h> int main() { int a[20],n,x,i,pos=0; printf(“Enter size of array:”); scanf(“%d”,&n); printf(“Enter the array in ascending order:\n”); for(i=0;i<n;++i) scanf(“%d”,&a[i]); printf(“\nEnter element to insert:”); scanf(“%d”,&x); for(i=0;i<n;++i) if(a[i]<=x&&x<a[i+1]) { pos=i+1; break; } for(i=n+1;i>pos;–i) a[i]=a[i-1]; a[pos]=x; …

C Program to Insert an Element in an Array Read More »

C Program to Find Sum of Elements Above and Below Main Diagonal of Matrix

Here is the simple C program to find sum of elements above and below main diagonal of matrix. The matrix should be square matrix. #include<stdio.h> int main() { int i,j,m,n,d1=0,d2=0,a[5][5]; printf(“How many rows and columns:”); scanf(“%d%d”,&m,&n); printf(“Enter matrix elements:\n”); for(i=0;i<m;++i) for(j=0;j<n;++j) { scanf(“%d”,&a[i][j]); if(j>i) d1+=a[i][j]; else if(i>j) d2+=a[i][j]; } printf(\n”Sum of elements above the diagonal=%d\n”,d1); …

C Program to Find Sum of Elements Above and Below Main Diagonal of Matrix Read More »

C++ program to swap two numbers using macros

#include<iostream.h> #include<conio.h> #define SWAP(a,b) {int temp; temp=a; a=b; b=temp;} void main() { clrscr(); int x,y; cout<<“Enter two numbers:”; cin>>x>>y; cout<<“x=”<<x<<” y=”<<y; SWAP(x,y); cout<<“nx=”<<x<<” y=”<<y; getch(); }

C++ program to enter a number and print it into words

#include<iostream.h> #include<conio.h> void once(int a) { switch(a) { case 1: cout<<“One”; break; case 2: cout<<“Two”; break; case 3: cout<<“Three”; break; case 4: cout<<“Four”; break; case 5: cout<<“Five”; break; case 6: cout<<“Six”; break; case 7: cout<<“Seven”; break; case 8: cout<<“Eight”; break; case 9: cout<<“Nine”; break; } } int tens(int a,int b) { int flag=0; switch(a) { …

C++ program to enter a number and print it into words Read More »