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 »

C program to find the sum of series 1/2+4/5+7/8+……

#include<stdio.h> #include<conio.h> void main() { int i,n; clrscr(); float sum=0,x,a=1; printf(“1/2+4/5+7/8+……”); printf(“nnHow many terms(ex: 1,2,3…n)?”); scanf(“%d”,&n); for(i=0;i<n;++i) { x=a/(a+1); sum+=x; a+=3; } printf(“nSum=%f”,sum); getch(); }

C program to swap two numbers without using temporary variable

#include<stdio.h> #include<conio.h> void main() { int x,y; clrscr(); printf(“Enter value of X: “); scanf(“%d”,&x); printf(“Enter value of y: “); scanf(“%d”,&y); if(x>y) { y=x-y; x=x-y; y=x+y; } else if(y>x) { x=y-x; y=y-x; x=y+x; } printf(“nx=%d”,x); printf(“ny=%d”,y); getch(); }

Convert Decimal to Binary in C

Here you will get program to convert decimal to binary in C. We can convert a decimal number into binary by repeatedly dividing it by 2 and storing the remainder somewhere. Now display the remainders in reverse order. Also Read: Convert Binary to Decimal in C Convert Decimal to Binary in C #include<stdio.h> int main() { …

Convert Decimal to Binary in C Read More »