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();
}
Program to check whether given string is palindrome or not
String is Palindrome Tuesday, August 11, 2020
Learn C++ (Introduction and Tutorials to C++ Programming)
//Program to check whether given string is palindrome or not
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{clrscr();
char str[30];
int i,j,len,flag;
cout<<"\n Enter The String :";
gets (str);
for(len=0; str [len]!='\0';++len);
cout<<"\n The Length of The String ="<<len;
for(i=0, j=len-1; i<len/2;i++,j--)
{if(str[i]!= str[j])
{flag =1;
cout <<"\n NOT A PALINDROME";
break;
}
}
if(flag==0)
cout<<"\n YES A PALINDROME";
getch();
}
//Program to check whether given string is palindrome or not
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{clrscr();
char str[30];
int i,j,len,flag;
cout<<"\n Enter The String :";
gets (str);
for(len=0; str [len]!='\0';++len);
cout<<"\n The Length of The String ="<<len;
for(i=0, j=len-1; i<len/2;i++,j--)
{if(str[i]!= str[j])
{flag =1;
cout <<"\n NOT A PALINDROME";
break;
}
}
if(flag==0)
cout<<"\n YES A PALINDROME";
getch();
}
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();
}
Program to Check the number is whether palindrome or not | C++ Programming
Palindrome or not Tuesday, August 11, 2020
//Program to Check the number is whether palindrome or not
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
long num,res=0,ori,c;
cout<<"\n Enter the number:";
cin>>num;
ori=num;
while(num>0)
{
c=num %10;
res=res*10+c;
num=num/10;
}
if(ori==res)
cout<<"\n The entered number is palindrome";
else
cout<<"\n The entered number is not palindrome";
getch();
}
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
long num,res=0,ori,c;
cout<<"\n Enter the number:";
cin>>num;
ori=num;
while(num>0)
{
c=num %10;
res=res*10+c;
num=num/10;
}
if(ori==res)
cout<<"\n The entered number is palindrome";
else
cout<<"\n The entered number is not palindrome";
getch();
}
//Program to check whether the entered number is even or odd using if else
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int n;
cout<<"\n Enter an Integer:";
cin>>n;
if(n%2==0)
{
cout<<n<<" Is Even ";
}
else
{
cout<<n<<" Is Odd";
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int n;
cout<<"\n Enter an Integer:";
cin>>n;
if(n%2==0)
{
cout<<n<<" Is Even ";
}
else
{
cout<<n<<" Is Odd";
}
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 input Square and Cube of an Integer
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int i,s,c;
cout<<"\n Enter The Integer:";
cin>>i;
s=i*i;
c=i*i*i;
cout<<"\n Square="<<s;
cout<<"\n Cube="<<c;
getch();
}
//Program to input Square and Cube of an Integer
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int i,s,c;
cout<<"\n Enter The Integer:";
cin>>i;
s=i*i;
c=i*i*i;
cout<<"\n Square="<<s;
cout<<"\n Cube="<<c;
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.
//Program to find Largest number of three Integer
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
int a,b,c,largest;
cout<<"\n enter the integer:";
cin>>a>>b>>c;
largest=(a>b)?(a>c?a:c):(b>c?b:c);
cout<<"\n largest integer is:"<<largest;
getch();
}
//Program to find Largest number of three Integer
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
int a,b,c,largest;
cout<<"\n enter the integer:";
cin>>a>>b>>c;
largest=(a>b)?(a>c?a:c):(b>c?b:c);
cout<<"\n largest integer is:"<<largest;
getch();
}
//Program to find the detail of n customer
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct address
{int HNO;
char street[10];
char city[20];
char pin[7];
};
struct date
{int dd;
int mm;
int yy;
};
struct directory
{int ID;
char name[20];
date DOB;
address ADDRESS;
};
void main()
{clrscr();
directory DIRC[10];
int n,id,flag=0;
cout<<"\n Enter the no of customer : ";
cin>>n;
for(int i=0;i<n;i++)
{cout<<"\n Enter customer Id : ";
cin>>(DIRC[i].ID);
cout<<"\n Enter customer name : ";
gets(DIRC[i].name);
cout<<"\n Enter Address ";
cout<<"\n Enter House No : ";
cin>>DIRC[i].ADDRESS.HNO;
cout<<"\n Enter Street : ";
cin>>DIRC[i].ADDRESS.street;
cout<<"\n Enter City : ";
cin>>DIRC[i].ADDRESS.city;
cout<<"\n Enter Pin : ";
cin>>DIRC[i].ADDRESS.pin;
cout<<"\n Enter date of birth : ";
cin>>(DIRC[i].DOB.dd);
cin>>(DIRC[i].DOB.mm);
cin>>(DIRC[i].DOB.yy);
}
cout<<"\n Enter ID to be Searched : ";
cin>>id;
for(i=0;i<n;i++)
{if(DIRC[i].ID==id)
{cout<<"\n customer id="<<DIRC[i].ID;
cout<<"\n customer name="<<DIRC[i].name;
cout<<"\n customer address=";
cout<<DIRC[i].ADDRESS.HNO<<","<<DIRC[i].ADDRESS.street<<","
<<DIRC[i].ADDRESS.city<<","<<(DIRC[i].ADDRESS.pin);
cout<<"\n customer DOB:";
cout<<(DIRC[i].DOB.dd)<<"/"<<(DIRC[i].DOB.mm)<<"/"<<(DIRC[i].DOB.yy);
flag=1;
}
}
if (flag==0)
cout<<"\n not found:";
getch();
}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct address
{int HNO;
char street[10];
char city[20];
char pin[7];
};
struct date
{int dd;
int mm;
int yy;
};
struct directory
{int ID;
char name[20];
date DOB;
address ADDRESS;
};
void main()
{clrscr();
directory DIRC[10];
int n,id,flag=0;
cout<<"\n Enter the no of customer : ";
cin>>n;
for(int i=0;i<n;i++)
{cout<<"\n Enter customer Id : ";
cin>>(DIRC[i].ID);
cout<<"\n Enter customer name : ";
gets(DIRC[i].name);
cout<<"\n Enter Address ";
cout<<"\n Enter House No : ";
cin>>DIRC[i].ADDRESS.HNO;
cout<<"\n Enter Street : ";
cin>>DIRC[i].ADDRESS.street;
cout<<"\n Enter City : ";
cin>>DIRC[i].ADDRESS.city;
cout<<"\n Enter Pin : ";
cin>>DIRC[i].ADDRESS.pin;
cout<<"\n Enter date of birth : ";
cin>>(DIRC[i].DOB.dd);
cin>>(DIRC[i].DOB.mm);
cin>>(DIRC[i].DOB.yy);
}
cout<<"\n Enter ID to be Searched : ";
cin>>id;
for(i=0;i<n;i++)
{if(DIRC[i].ID==id)
{cout<<"\n customer id="<<DIRC[i].ID;
cout<<"\n customer name="<<DIRC[i].name;
cout<<"\n customer address=";
cout<<DIRC[i].ADDRESS.HNO<<","<<DIRC[i].ADDRESS.street<<","
<<DIRC[i].ADDRESS.city<<","<<(DIRC[i].ADDRESS.pin);
cout<<"\n customer DOB:";
cout<<(DIRC[i].DOB.dd)<<"/"<<(DIRC[i].DOB.mm)<<"/"<<(DIRC[i].DOB.yy);
flag=1;
}
}
if (flag==0)
cout<<"\n not found:";
getch();
}
//Program to calculate the number of vowels
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include <ctype.h>
void CHARTYPE(char STRING[20]);
void main ()
{clrscr();
char string[20],ch;
cout<<"\n Enter a string:";
gets(string);
CHARTYPE(string);
getch();
}
void CHARTYPE(char string[20])
{char ch;
int len,v=0,c=0,o=0,d=0;
for(len=0;string[len]!='\0';++len)
{if(isalpha (string[len]))
{ch=toupper(string[len]);
if(ch=='A'||ch=='E'||ch=='I'||ch=='0'||ch=='U')
++v;
else
++c ;
}
else if (isdigit (string[len]))
++d;
else
++o;
}
cout<<"\n There are "<<v<<"vowels,"<<c<<"constants,"<<d<<"digit and"<<o<<"other character in the given string :";
}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include <ctype.h>
void CHARTYPE(char STRING[20]);
void main ()
{clrscr();
char string[20],ch;
cout<<"\n Enter a string:";
gets(string);
CHARTYPE(string);
getch();
}
void CHARTYPE(char string[20])
{char ch;
int len,v=0,c=0,o=0,d=0;
for(len=0;string[len]!='\0';++len)
{if(isalpha (string[len]))
{ch=toupper(string[len]);
if(ch=='A'||ch=='E'||ch=='I'||ch=='0'||ch=='U')
++v;
else
++c ;
}
else if (isdigit (string[len]))
++d;
else
++o;
}
cout<<"\n There are "<<v<<"vowels,"<<c<<"constants,"<<d<<"digit and"<<o<<"other character in the given string :";
}
Program to search a number in any integer array using user defined function
Array Tuesday, August 11, 2020
//program to search a number in any integer array using user defined function
#include<iostream.h>
#include<conio.h>
void SEARCH (int a[10],int n,int elements);
void main()
{clrscr();
int a[10],n, elements,i;
cout<<"\n Enter No. Of elements :";
cin>>n;
for (i=0;i<n;i++)
{cout<<"\n Enter a["<<i<<"] elements :";
cin>>a[i];
}
cout<<"\n The Array is :\n ";
for (i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<"\n Enter The element to be search :";
cin>>elements;
SEARCH (a,n, elements);
getch();
}
void SEARCH (int a[10], int n ,int elements)
{int i, flag= 0;
for(i=0; i<n; i++)
{if ( a[i]== elements)
{flag=1;
break;
}
}
if(flag==0)
cout<<"\n Unsuccessful Search ";
else
cout<<"\n element is found at index "<<i<<" and at position "<<(i+1);
}
#include<iostream.h>
#include<conio.h>
void SEARCH (int a[10],int n,int elements);
void main()
{clrscr();
int a[10],n, elements,i;
cout<<"\n Enter No. Of elements :";
cin>>n;
for (i=0;i<n;i++)
{cout<<"\n Enter a["<<i<<"] elements :";
cin>>a[i];
}
cout<<"\n The Array is :\n ";
for (i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<"\n Enter The element to be search :";
cin>>elements;
SEARCH (a,n, elements);
getch();
}
void SEARCH (int a[10], int n ,int elements)
{int i, flag= 0;
for(i=0; i<n; i++)
{if ( a[i]== elements)
{flag=1;
break;
}
}
if(flag==0)
cout<<"\n Unsuccessful Search ";
else
cout<<"\n element is found at index "<<i<<" and at position "<<(i+1);
}
//program to find the number prime or not
#include <iostream.h>
#include <conio.h>
int PRIME(int N);
void main()
{clrscr();
int i,n;
cout<<"\n Enter Any no :";
cin>>n;
int x=PRIME(n);
if(x==0)
cout<<"\n Not a Prime :";
else
cout<<"\n Yes It is Prime :";
getch();
}
int PRIME(int N)
{int I,FLAG=0;
for(I=2;I<N;I++)
{FLAG=N%I;
if( FLAG==0)
return 0;
}
return 1;
}
#include <iostream.h>
#include <conio.h>
int PRIME(int N);
void main()
{clrscr();
int i,n;
cout<<"\n Enter Any no :";
cin>>n;
int x=PRIME(n);
if(x==0)
cout<<"\n Not a Prime :";
else
cout<<"\n Yes It is Prime :";
getch();
}
int PRIME(int N)
{int I,FLAG=0;
for(I=2;I<N;I++)
{FLAG=N%I;
if( FLAG==0)
return 0;
}
return 1;
}