You are on page 1of 13

Last program (i.e.

12th) is incorrect
// A program to check wether the entered number is even or odd
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr();
int num;
cout<<"\n Enter a number to check wether it is even or odd : ";
cin>>num;
if (num%2==0)
cout<<"\n The entered number "<<num<<" is even . ";
else
cout<<"\n The entered number "<<num<<" is odd . ";
getch();
}
// A program to check wether the entered number is positive or negative

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num;
cout<<"\n Enter a number to check wether it is a positive or negative number : ";
cin>>num;
if(num>0)
cout<<"\n Entered number "<<num<<" is a positive number .";
if(num==0)
cout<<"\n Entered number is zero ";
if(num<0)
cout<<"\n Entered number "<<num<<" is a negative number .";
getch();
}
// A program for arithmetic operation using switch case(+ , - ,, * , / )
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr();
char s;
float a , b , c;
cout<<"\n Enter two numbers :" ;
cin>>a>>b;
cout<<"\n Enter the operation symbol ( + , - , * , / ) : ";
cin>>s;
switch (s)
{
case '+' : c=a+b;
break;
case '-' : c=a-b;
break;
case '*' : c=a*b;
break;
case '/' : c=a/b;
break;
default : cout<<"\n Invalid Option . ";
break;
}
cout<<"\n Result : "<<a<<" "<<s<<" "<<b<<" = "<<c;
getch();
}
//A program to reverse the entered number
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr();
int num , cnum , rnum=0 ;
cout<<"\n Enter a number to find its reverse : ";
cin>>num;
cnum=num;
do
{
rnum=( rnum*10) + cnum%10 ;
cnum=cnum/10 ;
} while (cnum!=0) ;
cout<<"\n Reverse number of "<<num<<" is : "<<rnum;
getch();
}
//A program to swap the entered number using function
#include<iostream.h>
#include<conio.h>
void swap ();
void main()
{
clrscr();
swap();
getch();
}
void swap()
{
int a, b;
cout<<"\n Enter two numbers : \n\n A = : ";
cin>>a;
cout<<"\n B = : ";
cin>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"\n Swaped numbers are : \n\n A = : "<<a<<"\n\n B = : "<<b;
}
// A program to check wether the entered number is palindrome or not without using
string.
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr();
int num , cnum , rnum=0 ;
cout<<"\n Enter a number to check wether its a palindrome or not : ";
cin>>num;
cnum=num;
do
{
rnum=( rnum*10) + cnum%10 ;
cnum=cnum/10 ;
} while (cnum!=0) ;
if (num == rnum)
cout<<"\n Enterd number "<<num<<" is a palindrome";
else
cout<<"\n Enterd number "<<num<<" is not a palindrome" ;
getch();
}
// A program to calculate the sum of two matrices of order m * n
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr();
int i, j, m , n, a[50][50] , b[50][50], c[50][50];
cout<<"\n Enter order of the matrices (less than 50*50) m*n : \n m = ";
cin>>m;
cout<<"\n n = ";
cin>>n;
cout<<"\n Enter the elements of matrix A of order "<<m<<"*"<<n<<" : \n";
for (i=0; i<m; i++) // For storing values of matrix A
{
for (j=0; j<n; j++)
{
cin>>a[i][j];
}
}
cout<<"\n Enter the elements of matrix B of order "<<m<<"*"<<n<<" : \n";
for (i=0; i<m; i++) // For storing values of matrix B
{
for (j=0; j<n; j++)
{
cin>>b[i][j];
}
}
cout<<"\n Entered elements of matrix A of order "<<m<<"*"<<n<<" is : \n";
for (i=0; i<m; i++) // For displaying matrix A
{
for (j=0; j<n; j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<"\n Entered elements of matrix B of order "<<m<<"*"<<n<<" is : \n";
for (i=0; i<m; i++) // For displaying matrix B
{
for (j=0; j<n; j++)
{
cout<<b[i][j]<<" ";
}
cout<<endl;
}
for (i=0; i<m; i++) //For Calculating sum of two matrices
{
for (j=0; j<n; j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
cout<<"\n Sum of matrix A and B is : \n";
for (i=0; i<m; i++) // For displaying sum of matrix
{
for (j=0; j<n; j++)
{
cout<<c[i][j]<<" ";
}
cout<<endl;
}
getch();
}
// A program to search an element in an array
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr();
int a[100], n, s;
cout<<"\n Enter lenghts of array (max 100) : ";
cin>>n;
cout<<"\n Enter the "<<n<<" elements of array : ";
for(int i=0; i<n; i++) // for storing array
cin>>a[i];
cout<<"\n Entered Array is : \n ";
for (i=0; i<n; i++) // for displaying array
{
cout<<a[i]<<" ";
}
cout<<"\n Enter the element to search in the array : ";
cin>>s;
int b=0;
for(i=0 ; i<n ; i++) // to search the element
{
if (s==a[i])
{
b=1;
break;
}
}
if (b==1)
cout<<"\n Element = "<<s<<" found .\n It is element no. "<<i+1<<" of the array ";
else
cout<<"\n Element = "<<s<<" not found.";
getch();
}
//A program to calculate simple interest n times
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
float p, r, t, si, a ;
cout<<"\n Enter the number of times you want to calculate the simple interest : ";
cin>>n;
for (int i=0 ; i<n ; i++)
{
cout<<"\n
_______________________________________________________________________
_ ";cout<<"\n\n\n\n Enter principal amount : Rs ";
cin>>p;
cout<<"\n Enter rate of interest (in %) : ";
cin>>r;
cout<<"\n Enter time priod ( in years ) : ";
cin>>t;
si=(p*r*t)/100; // formula for si
a=p+si; // formula for total amount
cout<<"\n\n Simple Interest = "<<si;
cout<<"\n\n Total Amount = "<<a;
}
getch();
}
// A program to calculate sum of odd numbers between 1 to 100
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int s=0, n=1, i;
do // To calculate sum
{
s=s+n;
n=n+2;
} while ( n<100) ;
cout<<"\n Sum of all the odd numbers between 1 to 100 is : "<<s;
getch();
}
// A program to insert an array and print it in reverse order
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr();
int a[100], n;
cout<<"\n Enter lenghts of array (max 100) : ";
cin>>n;
cout<<"\n Enter the "<<n<<" elements of array : \n";
for(int i=0; i<n; i++) // for storing array
cin>>a[i];
cout<<"\n Entered Array is : \n ";
for (i=0; i<n; i++) // for displaying array
cout<<a[i]<<" ";
cout<<"\n The array in reverse order is :\n ";
for(i=n-1 ; i>=0 ; i--) // for displaying it reverse order
cout<<a[i]<<" ";
getch();
}
// A program to find reverse of entered number using an array
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr();
int n, c, r=0, a[10];
cout<<"\n Enter a number : ";
cin>>n;
c=n;
for(int i=1 ; c!=0; i++)
{
a[i]=c%10;
c=c/10;
}
do
{
r=((r*10)+a[i]);
i--;
} while (i!=0) ;
cout<<"\n The reverse of number "<<n<<" using array is : "<<r;
getch();
}

You might also like