C program to print a message on the screen
#include<stdio.h> #include<conio.h> void main() { clrscr(); //to clear the screen printf(“nnnnttt***** Welcome to C Programming *****”); getch(); //to stop the screen }
#include<stdio.h> #include<conio.h> void main() { clrscr(); //to clear the screen printf(“nnnnttt***** Welcome to C Programming *****”); getch(); //to stop the screen }
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();}
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 »
Here is the C++ program to insert an element in an array. The array must be in ascending order. For example the array is 1 4 6 7. We have to insert 5. Then the resultant array will be 1 4 5 6 7. The program is given below. C++ Program to Insert an Element …
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 …
#include<iostream.h> #include<conio.h>void main() { clrscr(); int a,b; cout<<“Enter value of a:”; cin>>a; cout<<“Enter value of b:”; cin>>b; a=a+b; b=a-b; a=a-b; cout<<“na=”<<a; cout<<“nb=”<<b; getch(); }
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 »
Here is the C++ program to find largest and second largest number in a 2d array or matrix. #include<iostream> using namespace std; int main() { int a[5][5],big1=1,big2=0,n,m,i,j; cout<<“Enter no of rows and columns(max 5):”; cin>>m>>n; cout<<“Enter the array:\n”; for(i=0;i<m;i++) for(j=0;j<n;++j) cin>>a[i][j]; for(i=0;i<m;++i) for(j=0;j<n;++j) { if(a[i][j]>big1) big1=a[i][j]; } for(i=0;i<m;++i) for(j=0;j<n;++j) { if(a[i][j]>big2&&a[i][j]<big1) big2=a[i][j]; } cout<<“\nLargest number:”<<big1; …
C++ Program to Find Largest and Second Largest Number in 2D Array Read More »