Tuesday 12 April 2016

Write a program in c++ to find multiplication of two nos using function.

//wap in c++ to find multiplication of two nos using function.


Coding:-

#include<iostream.h>
#include<conio.h>

int mul(int num1,int num2);
int main()
{
clrscr();

int a,b;
cout<<"enter first no";
cin>>a;
cout<<"\n enter second no";
cin>>b;
int ret;
ret=mul(a,b);
cout<<"multiplication of two nos is:"<<ret;
getch();
return 0;
}

int mul(int num1,int num2)
{
int result;
result=num1*num2;
return result;
}
Output:-

Write a Program in c++ to find max no among two using function.

//wap in c++ to find max no among two using function.
 



Coding:-

#include<iostream.h>
#include<conio.h>

int max(int num1,int num2); //function Declaration
int main()
{
clrscr();



int a,b;
cout<<"enter first no:";
cin>>a;
cout<<"\n enter second no:";
cin>>b;
int ret;
ret=max(a,b);  //function call
cout<<"max value is:"<<ret;
getch();
return 0;
}
int max(int num1,int num2)
{
int result;
if(num1 > num2)
{
result=num1;
}
else
{
result = num2;
}
return result;
}



Output:- 





Wednesday 6 April 2016

Write a program in c++ to print reverse no using do while loop.

//wap in c++ to print reverse no using do while loop.
 


 Coding:-

#include<iostream.h>
#include<conio.h>

void main()
{

clrscr();
int a,digit;
cout<<"enter any no to find its reverse no";
cin>>a;
do
{

digit=a%10;
cout<<digit;
a=a/10;
}
while(a>0);
getch();
}



Output:- 


Write a Program in c++ to find quitient ,reminder untill 'no'is entered by user using do while loop.

//wap in c++ to find quitient ,reminder untill 'no'is entered by user using do while loop
 


 Coding:-

#include<iostream.h>
#include<conio.h>

void main()
{
int a,b,c,d;
char ch;
do{
cout<<"enter dividend";
cin>>a;
cout<<"enter divisor";
cin>>b;
c=a/b;
d=a%b;
cout<<"quotient="<<c<<"\n";
cout<<"reminder="<<d<<"\n";
cout<<"you want to do any other calculations please enter  y or n ";
cin>>ch;
}
while(ch!='n');

getch(); 
}

Output:-
 


 

write a program in c++ to find product of n natural no's using do while loop.

//wap in c++ to find product of n natural no's using do while loop.

Coding:-

#include<iostream.h>
#include<conio.h>

void main()
{

int i=1,n,prod=1;
cout<<"enter the no";
cin>>n;
do{
prod=prod*i;
i++;
}
while(i<=n);
cout<<"product="<<prod;
getch();
}
Output:-

 

Tuesday 5 April 2016

Program in c++ to print febonacci series upto 100 using while loop.

//wap in c++ to print febonacci series upto 100 using while loop.


 Coding:-

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

int a=1,b=0,c;
c=a+b;
cout<<c;
while(c<=100)
{
a=b;
b=c;
c=a+b;
cout<<" "<<c;
}
getch();
}


Output:- 



Write a Program in c++ to find sum of n natural no's using while loop.

//wap in c++ to find sum of n natural no's using while loop.
 



 Coding:-
#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

int i=1,n,sum=0;
cout<<"enter the no";
cin>>n;
while(i<=n)
{
sum=sum+i;
i++;
}
cout<<"sum="<<sum;
getch();
}


Output:- 

Program to find area of circle untill the entered radius is zero by using while loop.

//Wap to find area of circle untill the entered radius is zero by using while loop.
 

Coding:-
#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

float a,r,pi=3.14;
cout<<"enter the radius of circle";
cin>>r;
while(r!=0)
{
a=(pi)*r*r;
cout<<"the area is"<<a<<endl;
cout<<"enter the radius again";
cin>>r;
}
getch();
}


Output:- 
 

Program to print following pattern using for loop in c++ language.

 //Wap to print following pattern using for loop in c++ language.
   //              *
   //           *     *
   //         *    *    *
  //       *    *     *     *
  //          *    *     *
  //             *    *
  //               *




#include<iostream.h>
#include<conio.h>

void main()
{

int i,j,k,n;
clrscr();
cout<<"enter the no of rows:"<<endl;
for(i=1; i<=5; i++)
{
for( j=1;j<=5-i; j++)
{
cout<<"  ";
}
for(k=1; k<=i; k++)
{
cout<<" *  ";
}
cout<<"\n";
}
for(i=4;i>=1;i--)
{
for(j=1;j<=5-i;j++)
{
cout<<"  ";
}
for(k=1;k<=i;k++)
{
cout<<" ";
}
cout<<"\n";
}

getch();
}



Output:-

 

Thursday 31 March 2016

Program to print pattern using for loop in c++ language.

 Wap to print following pattern using for loop in c++ language.
   //              *
   //            *   *
   //          *   *   * 
  //         *   *   *   *


Coding:-

#include<iostream.h>
#include<conio.h>

void main()
{

clrscr();
cout<<"enter the no of rows:";
cin>>n;
for(i=1; i<=n; i++)
{
for( j=n-i;j>=1; j--)
{
cout<<" ";
}
for(k=1; k<=i; k++)
{
cout<<"* ";
}
cout<<"\n";
}

getch();
}

Output:

 

Program to print table from 1 to 9 using for loop in c++ language.

Wap to print table from 1 to 9 using for loop in c++ language.









Coding:


#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

int i,j,k;
for(i=1;i<=9;i++)
{
for(j=1;j<=10;j++)
{
k=i*j;
cout<<k<<" ";
}
cout<<"\n";
}getch();
}

Output:
 

Program to print 1 23 456 78910 pattern using for loop in C++ Language.

Wap to print following pattern using for loop in C++ Language.
 

// 1
// 2 3
// 4 5 6
// 7 8 9 10
// 11 12 13 14


Coding:-
 
#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

int i,j,n=1;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
cout<<n;
n++;
}
cout<<"\n";
}getch();
}


Output:-

Program to print pattern 1 22 333 4444 5555 using for loop in c++ language.

 //Wap to print following pattern using for loop in c++ language.

   //   1

   //   2 2

   //   3 3 3

  //    4 4 4 4

  //    5 5 5 5 5


Coding:-
 
#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

int i,j,n;

cout<<"Enter the value of n";

cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
cout<<i;
}
cout<<"\n";
}getch();
}

Output:-
 

Wednesday 30 March 2016

Program to print following pattern using for loop in c++ language.

// Wap to print following pattern using for loop in c++ language.
      1
      1 2
      1 2 3
      1 2 3 4
      1 2 3 4 5

Coding:-
#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

int i,j,n;

cout<<"Enter the value of n";
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
cout<<j;

}
cout<<"\n";
}getch();
}

Output:-
                       

Tuesday 29 March 2016

Write a program to form table of 2 using for loop in c++ language.

//wap to form table of 2 using for loop in c++ language.
 

#include<iostream.h>
#include<conio.h>

void main()
{

clrscr();

int a=2,b=1,c,n;
cout<<"Table of 2 is :-"<<endl;
for(n=1;n<=10;n++)
{
c=a*b;
cout<<a<<"*"<<b<<"="<<c<<"\n";
b=b+1;
}getch();
}

Output:-
               
 



 

Write a program to calculate the factorial of a given number in c++ language.

//WAP to calculate the factorial of a given number in c++ language.
#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

int i,fact=1,n;
cout<<"enter number to find its factorial"<<" ";
cin>>n;
for(i=2;i<=n;i++)
{
fact=fact*i;
}
cout<<"factorial of nos is"<<fact;
getch();
}

output:-

                 

 

Write a Program to print even nos upto 100 using for loop in c++ language.

//wap  to print even nos up to 100 using for loop in c++ language.
#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

int a;
cout<<"Even nos are:"<<endl;
for(a=1;a<=100;a++)
{
if(a%2==0)
{
cout<<a<<" ";
}
}
getch();
}

Output:-
               

Program to calculate sum of n nos using for loops in c++ language.

//WAP to calculate sum of n nos using for loops in c++ language.
 

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

int i,n,sum=0;
cout<<"enter the value of n:"<<endl;
cin>>n;

for(i=1;i<=n;i++)
{
sum=sum+i;
}
cout<<"the sum of n nos is:"<<sum;

getch();
}

Output:-
                          

Write a program to print even nos upto 100 using for loop in c++ language.

//wap  to print even nos upto 100 using for loop in c++ language.
#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

int a;
cout<<"Numbers 1 to 10 are :"<<"\n";
for(a=1;a<=10;a++)
{
cout<<"\n"<<a;
}
getch();
}


Output:-
                     

Program to find out number of days in a month using switch case conditon in c++ language.

//WAP to find out number of days in a month using switch case.

#include<iostream.h>
#include<conio.h>

void main()
{

clrscr();
int m,y;
cout<<"enter month no."<<endl;
cin>>m;
cout<<"enter year"<<endl;
cin>>y;
switch(m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:

cout<<"No of days in this month is 31"<<endl;
break;

case 4:
case 6:
case 9:
case 11:

cout<<"No of days in this month is 30"<<endl;
break;
case 2: 

if(y%4==0)
{

cout<<"it is a leap year"<<endl;
cout<<"so no of days is 29"<<endl;
}
else
cout<<"no of days in a month is 28"<<endl;
break;
default:
cout<<"error"<<endl;
break;
}
getch();
}


Output:-
            

Program to print different calculations using switch case condition in c++ language.

//WAP to print different calculations using switch case.
 

#include<iostream.h>
#include<conio.h>

void main()
{

clrscr();

int a,b,d;
char ch;
cout<<"enter the values of a and b";
cin>>a>>b;
cout<<"enter the operator or case";
cin>>ch;
switch(ch)
{
case '+':
d=a+b;
cout<<"sum of a and b is:"<<" "<<d<<endl;
break;
case '*':
d=a*b;
cout<<"multiplication of a and b is:"<<" "<<d<<endl;
break;
case '-':
d=a-b;
cout<<"subtraction of a and b is:"<<" "<<d<<endl;
break;
case '/':
d=a/b;
cout<<"division of a and bis:"<<" "<<d<<endl;
break;
default:
cout<<"wrong case no calculations:"<<endl;
break;
}
getch();
}


Output:-
                                         

Program to print the days of weeks by using switch case in c++ language.

//WAP to print the days of weeks by using switch case.
 
#include<iostream.h>
#include<conio.h>

void main()
{

clrscr();

int c;
cout<<"enter any case";
cin>>c;
switch(c)
{
case 1:
cout<<"monday"<<endl;
break;
case 2:
cout<<"tuesday"<<endl;
break;
case 3:
cout<<"wednesday"<<endl;
break;
case 4:
cout<<"thrusday"<<endl;
break;
case 5:
cout<<"friday"<<endl;
break;
case 6:
cout<<"saturday"<<endl;
break;
default:
cout<<"error"<<endl;
break;
}
getch();
}

Output:-
               

Program to calculate division obtain by students using else if condition statement in c++ language.

//WAP  to calculate division obtain by students using else if condition statement.
#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

int m1,m2,m3,per;
cout<<"enter the marks of enlish";
cin>>m1;
cout<<"enter the marks of maths";
cin>>m2;
cout<<"enter the manrks of science";
cin>>m3;
per=(m1+m2+m3)/3;
if(m1>=40 && m2>=40 && m3>=40)
{
if(per>=60)
{
cout<<"first division"<<per<<" "<<per<<"%";
}
else if(per>=50)
{
cout<<"second division"<<" "<<per<<"%";
}
else if(per>=40)
{
cout<<"third division"<<" "<<per<<"%";
}
}
else
{
cout<<"you are fail in one or more subjects";
}

getch();
}


Output:- 
              

Monday 28 March 2016

Write a program to Check Whether Number is Even or Odd using C++ Language.

//Write a program  to Check Whether Number is Even or Odd.

#include <iostream.h>
#include<conio.h>

int main()
{
    clrscr();

    int num;
    cout << "Enter an integer: ";
    cin >> num;
    if ( num%2 == 0)
 {
        cout << num << " is even.";
 }
    else
{
        cout << num << " is odd.";

 
    getch();

    return 0;
}


Output:-

                
 

Write a program to perform celsius to fahrenheit conversion using C++ language.

// Write a program to perform Celsius to Fahrenheit conversion.

#include<iostream>
#include<conio.h>
int main()
{
    clrscr();

    float fahrenheit, celsius;
    cout << "Enter the temperature in Celsius : ";
    cin >> celsius;

    fahrenheit = (celsius * 9.0) / 5.0 + 32;

    cout<<"The temperature in Celsius : " << celsius << endl;

    cout<<"The temperature in Fahrenheit:" << fahrenheit << endl;

    getch();
    return 0;

}


Output:-
          

Write a program to find simple interest using C++ language.

// Write a program to find simple interest.

#include<iostream.h>
#include<conio.h>

int main()
{   
   
    clrscr();
    int p,t;
    float r,si;
    cout<<"Enter Principle : ";
    cin>>p;
    cout<<"Enter Rate : ";
    cin>>r;
    cout<<"Enter Time : ";
    cin>>t;
    si=(p*r*t)/100;
    cout<<"Simple interest is : "<<si;

    getch();
    return (0);
}

OutPut:-



Wednesday 23 March 2016

Write a Program to ADD , MULTIPLY , SUBTRACT and DIVIDE two no's.

//Write A Program to ADD , MULTIPLY , SUBTRACT and DIVIDE two no's.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,add,sub,mul,div;
cout<<"Enter first no or value of a=";
cin>>a;
cout<<"Enter second no or value of b=";
cin>>b;
add=a+b;
sub=a-b;
mul=a*b;
div=a/b;
cout<<"Sum of a & b ="<<add<<endl;
cout<<"Subtraction of a & b ="<<sub<<endl;
cout<<"Multiplication of a & b ="<<mul<<endl;
cout<<"Division of a & b ="<<div<<endl;
getch();
}

 OutPut:-