C++ is one of the most popular programming languages. It is based on C but is an object-oriented programming language. It is widely used in graphics libraries, games, network devices, etc.
//Program to find the positive number
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int num,i,sum;
cout<<"\n enter the positive number:";
cin>> num;
i=1;
sum=0;
start:
sum=sum+i;
i++;
if(i<=num)
goto start;
cout<<sum;
getch();
}
C++ is a general-purpose programming language. It has imperative, object-oriented and generic programming features, while also providing facilities for low-level memory manipulation.
//Program to generate the Fibonacci series
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int x=0,y=1,z,n,i=3;
cout<<"\n Enter The Number Of Term :";
cin>>n;
cout<<x<<" "<<y<<" ";
do
{z=x+y;
cout<<z<<" ";
x=y;
i++;
}while(i<=n);
getch();
}
//Program to find product of two matrices
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int A[10][10],B[10][10],C[10][10],m,n,p,q,i,k,j;
cout<<"\n enter the size of first matrix :";
cin>>m>>n;
cout<<"\n enter the size of second matrix :";
cin>>p>>q;
if(n==p)
{
cout<<"\n product of two matrix is possible ";
cout<<"\n enter the elements of first matrix ";
{
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
cout<<"\n enter A["<<i<<"]["<<j<<"]";
cin>>A[i][j];
}
}
cout<<"\n enter the elements of second matrix";
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
cout<<"\n enter B["<<i<<"]["<<j<<"]";
cin>>B[i][j];
}
}
cout<<"\n the first matrix is :";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
cout<<A[i][j]<<" ";
}
cout<<"\n second matrix is:";
for(i=0;i<p;i++)
{
cout<<"\n ";
for(j=0;j<q;j++)
cout<<B[i][j]<<" ";
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
C[i][j]=0;
}
for(i=0;i<m;i++)
for(j=0;j<q;j++)
for(k=0;k<n;k++)
{
C[i][j]+=A[i][k]*B[k][j];
}
}
cout<<"\n the product of two matrix is :";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<q;j++)
cout<<C[i][j]<<" ";
}
}
else
cout<<"\n multiplication is not possible:";
getch();
}
//Program to find diagonal of matrix
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int A[10][10],B[10][10],m,n,i,j;
cout<<"\n enter the no. of rows:";
cin>>m;
cout<<"\n enter no. of column:";
cin>>n;
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
{ cout<<"/n enter A["<<i<<"]["<<j<<"] element:";
cin>>A[i][j];
}
}
cout<<"/n the matrix is:";
for(i=0;i<m;i++)
{ cout<<"\n";
for(j=0;j<n;j++)
cout<<A[i][j]<<" ";
}
cout<<"/n first diagonal is:\n";
for(i=0;i<n;i++)
{ for(j=0;j<m;j++)
{ if(i==j)
cout<<A[i][j]<<" ";
}
}
cout<<"\n second diagonal is:";
for(i=0;i<n;i++)
{ for(j=0;j<m;j++)
{ if(i+j==n-1)
cout<<A[i][j]<<" ";
}
}
int sum1=0,sum2=0;
for(i=0;i<n;i++)
{ for(j=0;j<m;j++)
{ if(i==j)
sum1+=A[i][j];
if(i+j==n-i)
sum2+=A[i][j];
}
}
cout<<"\n sum of first diagonal element="<<sum1;
cout<<"\n sum of second diagonal element="<<sum2;
if(i==j)
{ cout<<A[i][j]<<" ";
sum1+=A[i][j];
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int A[10][10],B[10][10],m,n,i,j;
cout<<"\n enter the no. of rows:";
cin>>m;
cout<<"\n enter no. of column:";
cin>>n;
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
{ cout<<"/n enter A["<<i<<"]["<<j<<"] element:";
cin>>A[i][j];
}
}
cout<<"/n the matrix is:";
for(i=0;i<m;i++)
{ cout<<"\n";
for(j=0;j<n;j++)
cout<<A[i][j]<<" ";
}
cout<<"/n first diagonal is:\n";
for(i=0;i<n;i++)
{ for(j=0;j<m;j++)
{ if(i==j)
cout<<A[i][j]<<" ";
}
}
cout<<"\n second diagonal is:";
for(i=0;i<n;i++)
{ for(j=0;j<m;j++)
{ if(i+j==n-1)
cout<<A[i][j]<<" ";
}
}
int sum1=0,sum2=0;
for(i=0;i<n;i++)
{ for(j=0;j<m;j++)
{ if(i==j)
sum1+=A[i][j];
if(i+j==n-i)
sum2+=A[i][j];
}
}
cout<<"\n sum of first diagonal element="<<sum1;
cout<<"\n sum of second diagonal element="<<sum2;
if(i==j)
{ cout<<A[i][j]<<" ";
sum1+=A[i][j];
}
getch();
}
C++ is one of the most popular programming languages. It is based on C but is an object-oriented programming language. It is widely used in graphics libraries, games, network devices, etc. C++ is a general-purpose programming language. It has imperative, object-oriented and generic programming features, while also providing facilities for low-level memory manipulation.
//Program to check whether the number is string or not
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{clrscr();
char string[10];
int i;
cout<<"\n enter the string:";
gets(string);
for(i=0;string[i]!='\0';i++)
{if(string[i]>=65 && string[i]<=92)
string[i]=string[i]+32;
string[i]=string[i];
}
cout<<"\n the converted string is:"<<string;
getch();
}
//Program to check whether the number is string or not
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{clrscr();
char string[10];
int i;
cout<<"\n enter the string:";
gets(string);
for(i=0;string[i]!='\0';i++)
{if(string[i]>=65 && string[i]<=92)
string[i]=string[i]+32;
string[i]=string[i];
}
cout<<"\n the converted string is:"<<string;
getch();
}
//Program to display the sum of each row elements
#include<iostream.h>
#include<conio.h>
#include <math.h>
void main()
{ clrscr();
int P[10][10],m,n,i,j,sum1=0;
cout<<"\n enter the no of rows for P:";
cin>>m;
cout<<"\n enter the no of columns for P:";
cin>>n;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<"\n enter P["<<i<<"]["<<j<<"] elements:";
cin>>P[i][j];
}
}
cout<<"\n the matrix P is:";
for (i=0;i<m; i++)
{cout<<"\n";
for(j=0; j<n; j++)
cout<<P[i][j]<<" ";
}
for(i=0;i<m; i++)
{sum1=0;
for(j=0; j<n; j++)
sum1+=P[i][j];
cout<<"\n Sum of row"<<i+1<<"="<<sum1;
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include <math.h>
void main()
{ clrscr();
int P[10][10],m,n,i,j,sum1=0;
cout<<"\n enter the no of rows for P:";
cin>>m;
cout<<"\n enter the no of columns for P:";
cin>>n;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<"\n enter P["<<i<<"]["<<j<<"] elements:";
cin>>P[i][j];
}
}
cout<<"\n the matrix P is:";
for (i=0;i<m; i++)
{cout<<"\n";
for(j=0; j<n; j++)
cout<<P[i][j]<<" ";
}
for(i=0;i<m; i++)
{sum1=0;
for(j=0; j<n; j++)
sum1+=P[i][j];
cout<<"\n Sum of row"<<i+1<<"="<<sum1;
}
getch();
}