Program to find the length of a string without using library function
Library Function Tuesday, August 11, 2020
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. 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 length of a string without using library function
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{clrscr();
char str[30];
int len;
cout<<"\n Enter a String :";
gets(str);
for(len=0;str(len)!='\0';++len);
cout<<"\n The Length of The String="<<len;
getch();
}
//Program to find the length of a string without using library function
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{clrscr();
char str[30];
int len;
cout<<"\n Enter a String :";
gets(str);
for(len=0;str(len)!='\0';++len);
cout<<"\n The Length of The String="<<len;
getch();
}
Program to find the transpose of m*n Matrix | C++ Programming
Transpose of Matrix Tuesday, August 11, 2020
//Program to find the transpose of m*n 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 The No. of columns :";
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]<<" ";
}
for(i=0;i<n;i++)
{for(j=0;j<m;j++)
B[i][j]=A[j][i];
}
cout<<"\n The Transpose Matrix Is :";
for(i=0;i<n;i++)
{cout<<"\n";
for(j=0;j<m;j++)
cout<<B[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 The No. of columns :";
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]<<" ";
}
for(i=0;i<n;i++)
{for(j=0;j<m;j++)
B[i][j]=A[j][i];
}
cout<<"\n The Transpose Matrix Is :";
for(i=0;i<n;i++)
{cout<<"\n";
for(j=0;j<m;j++)
cout<<B[i][j] <<"";
}
getch();
}
Program to find the sum of two matrices | C++ Programming
Sum of Two Matrices Tuesday, August 11, 2020
//Program to find the sum 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,j;
cout<<"\n enter the no of rows for A:";
cin>>m;
cout<<"\n enter the no of columns for A:";
cin>>n;
cout<<"\n enter the no of rows for B:";
cin>>p;
cout<<"\n enter the no of columns for B:";
cin>>q;
if(m==p && n==q)
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{cout<<"\n enter A["<<i<<"]["<<j<<"] elements:";
cin>>A[i][j];
}
}
cout<<"\n the matrix A is:";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
cout<<A[i][j]<<" ";
}
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
cout<<"\n enter B["<<i<<"]["<<j<<"] elements:";
cin>>B[i][j];
}
}
cout<<"\n the matrix B 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<n;j++)
C[i][j]=A[i][j]+B[i][j];
}
cout<<"\n the sum of the two is:";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
cout<<C[i][j]<<" ";
}
}
else
{
cout<<"\n the two are not equal and hence not be added:";
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int A[10][10],B[10][10],C[10][10],m,n,p,q,i,j;
cout<<"\n enter the no of rows for A:";
cin>>m;
cout<<"\n enter the no of columns for A:";
cin>>n;
cout<<"\n enter the no of rows for B:";
cin>>p;
cout<<"\n enter the no of columns for B:";
cin>>q;
if(m==p && n==q)
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{cout<<"\n enter A["<<i<<"]["<<j<<"] elements:";
cin>>A[i][j];
}
}
cout<<"\n the matrix A is:";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
cout<<A[i][j]<<" ";
}
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
cout<<"\n enter B["<<i<<"]["<<j<<"] elements:";
cin>>B[i][j];
}
}
cout<<"\n the matrix B 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<n;j++)
C[i][j]=A[i][j]+B[i][j];
}
cout<<"\n the sum of the two is:";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
cout<<C[i][j]<<" ";
}
}
else
{
cout<<"\n the two are not equal and hence not be added:";
}
getch();
}
Program to sort an Integer Array in descending order | C++ Programming
Integer Array Tuesday, August 11, 2020
//Program to sort an Integer Array in descending order
#include <iostream.h>
#include <conio.h>
void main()
{clrscr();
int n,i,j,B[10],temp ;
cout <<"\n enter the number of element :";
cin>>n;
for (i=0; i<n ; i++)
{cout <<"\n enter B["<<i<<"] element :";
cin>>B[i];
}
cout <<"\n original array :";
for (j=0; j<n; j++)
cout <<"\n B["<<j<<"]="<<B[j];
for(i=0;i<n; i++)
{for(j=0;j<n-i-1; j++)
{if(B[j] <B[j+1])
{temp=B[i];
B[j]=B[j+1];
B[j+1]=temp;
}
}
}
cout<<"\n decending order of array is :";
for(j=0;j<n;j++)
cout<< B[j]<<">";
getch();
}
#include <iostream.h>
#include <conio.h>
void main()
{clrscr();
int n,i,j,B[10],temp ;
cout <<"\n enter the number of element :";
cin>>n;
for (i=0; i<n ; i++)
{cout <<"\n enter B["<<i<<"] element :";
cin>>B[i];
}
cout <<"\n original array :";
for (j=0; j<n; j++)
cout <<"\n B["<<j<<"]="<<B[j];
for(i=0;i<n; i++)
{for(j=0;j<n-i-1; j++)
{if(B[j] <B[j+1])
{temp=B[i];
B[j]=B[j+1];
B[j+1]=temp;
}
}
}
cout<<"\n decending order of array is :";
for(j=0;j<n;j++)
cout<< B[j]<<">";
getch();
}
//Program to find the Sum of Series
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{clrscr();
float x,sum,term,fact=1;
int i,n;
cout<<"\n enter the value of x and n:";
cin>>x>>n;
sum=1;term=1;
for(i=1;i<=n;i++)
{fact=fact*i;
term=term+(x/fact);
sum=sum+term;
}cout<<"\n sum of the series="<<sum;
getch();
}
Or
#include <iostream.h>
#include <conio.h>
#include <math.h>
void main()
{clrscr();
long x,n,i,sum=0,term;
cout<<"\n enter the x:";
cin>>x;
cout<<"\n enter the n:";
cin>>n;
for(i=1;i<=n;i++)
{
term=pow(x,i);
sum=sum+term;
}
cout<<"\n enter the sum="<<sum;
getch();
}
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{clrscr();
float x,sum,term,fact=1;
int i,n;
cout<<"\n enter the value of x and n:";
cin>>x>>n;
sum=1;term=1;
for(i=1;i<=n;i++)
{fact=fact*i;
term=term+(x/fact);
sum=sum+term;
}cout<<"\n sum of the series="<<sum;
getch();
}
Or
#include <iostream.h>
#include <conio.h>
#include <math.h>
void main()
{clrscr();
long x,n,i,sum=0,term;
cout<<"\n enter the x:";
cin>>x;
cout<<"\n enter the n:";
cin>>n;
for(i=1;i<=n;i++)
{
term=pow(x,i);
sum=sum+term;
}
cout<<"\n enter the sum="<<sum;
getch();
}
//Program to Calculate Area of Circle, a Rectangle or a Square
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
int r,L,B,s;
int ch;
float area;
cout<<"\n press 1 for circle";
cout<<"\n press 2 for rectangle";
cout<<"\n press 3 for square";
cout<<"\n enter your choice :";
cin>>ch;
switch(ch)
{case 1:cout<<"\n enter the radius:";
area=3.14*r*r;
cout<<"\n"<<"the area of the circle is"<<area<<"\n";
break;
case 2:cout<<"\n enter length and breadth of rectangle:";
cin>>L>>B;
area=L*B;
cout<<"\n"<<"the area of rectangle is"<<area<<"\n";
break;
case 3:cout<<"\n enter the sides of square:";
cin>>s;
area=(s*s);
cout<<"\n"<<"the area of the square is"<<area<<"\n";
break;
default:cout<<"\n wrong choice entered";
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
int r,L,B,s;
int ch;
float area;
cout<<"\n press 1 for circle";
cout<<"\n press 2 for rectangle";
cout<<"\n press 3 for square";
cout<<"\n enter your choice :";
cin>>ch;
switch(ch)
{case 1:cout<<"\n enter the radius:";
area=3.14*r*r;
cout<<"\n"<<"the area of the circle is"<<area<<"\n";
break;
case 2:cout<<"\n enter length and breadth of rectangle:";
cin>>L>>B;
area=L*B;
cout<<"\n"<<"the area of rectangle is"<<area<<"\n";
break;
case 3:cout<<"\n enter the sides of square:";
cin>>s;
area=(s*s);
cout<<"\n"<<"the area of the square is"<<area<<"\n";
break;
default:cout<<"\n wrong choice entered";
}
getch();
}

