C Program to Add Two Numbers

Here you will get simple C program to add two numbers. User will input two numbers, then their sum will be calculated and finally it will be printed on screen. The program is given below. C Program to Add Two Numbers  #include<stdio.h> int main() { int a,b,sum; printf(“Enter first number:”); scanf(“%d”,&a); printf(“Enter second number:”); scanf(“%d”,&b); …

C Program to Add Two Numbers Read More »

C++ program to print the following design

AABABCABCDABCDE Code:#include<iostream.h>#include<conio.h> void main(){ int i,j,n; char ch; cout<<“How many lines(ex 5):”; cin>>n; for(i=0;i<n;++i) { for(j=0;j<i;++j) { ch=65+j; cout<<ch; } cout<<“n”; } getch();}

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

Here is the C++ program to find sum of elements above and below the main diagonal of square matrix. #include<iostream> using namespace std; int main() { int arr[5][5],a=0,b=0,i,j,n; cout<<“Enter size of matrix(max 5):”; cin>>n; cout<<“Enter the matrix:\n”; for(i=0;i<n;++i) for(j=0;j<n;++j) cin>>arr[i][j]; for(i=0;i<n;++i) for(j=0;j<n;++j) if(j>i) a+=arr[i][j]; else if(i>j) b+=arr[i][j]; cout<<“\nSum of elements above the diagonal:”<<a; cout<<“\nSum of …

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

Stack in C++ Using Linked List

Here you will learn about stack in C++ using a program example. Stack is an abstract datatype which follows Last In First Out (LIFO) principle. Basically stack has two operations namely push and pop.  push: inserting an element at the top of the stack pop: removing an element from the top of the stack Below …

Stack in C++ Using Linked List Read More »

C++ Program to Print Upperhalf and Lowerhalf Triangle of Square Matrix

Here is the C++ program to print upperhalf and lowerhalf triangle of a square matrix. #include<iostream> using namespace std; int main() { int a[10][10],i,j,m; cout<<“Enter size of the Matrix(min:3,max:5):”; cin>>m; cout<<“\nEnter the Matrix row wise:\n”; for(i=0;i<m;i++) for(j=0;j<m;++j) cin>>a[i][j]; cout<<“\n\n”; for(i=0;i<m;++i) { for(j=0;j<m;++j) { if(i<j) cout<<a[i][j]<<” “; else cout<<” “; } cout<<“\n”; } cout<<“\n\n”; for(i=0;i<m;++i) { …

C++ Program to Print Upperhalf and Lowerhalf Triangle of Square Matrix Read More »