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:-