Showing posts with label cplusplus programs. Show all posts
Showing posts with label cplusplus programs. Show all posts

Wednesday, 9 April 2014

write program that inputs divident and divisor.it then calculate and displays the quotient and remainder

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
 
 
 
#include<iostream.h>
#include<conio.h>
void main(){
int div ,dis, q , r;
clrscr();
cout<<enter divident  ";
cin>>div;
cout<<enter  divisor ";
cin>>dis;
q=div/dis;
r=div%dis;
cout<<"quotient="<<q<<endl;
cout<<"remainder="<<r;
getch();
} 
 
 
 




OUTPUT

Wednesday, 9 April 2014 by gul ahmad · 0

Write a c++ program to add two numbers without using addition operator.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int a,b;
int sum;
cout<<"Enter any two integers:\n ";
cout<<"Enter first integers= ";
cin>>a;
cout<<"Enter second integers= ";
cin>>b;
sum = a - (-b);
//sum = a - ~b -1;
cout<<"Sum of two integers:"<<sum;
getch();
}


OUTPUT

by gul ahmad · 0

write c++ program that display a numbers with their squares


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int n;
n=1;
while(n<=5)
{
cout<<n<<"\t"<<n*n<<endl;
n++;
}
getch();
}



OUTPUT

by gul ahmad · 0

write c++ program that display first five numbers and their sum


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int n=1,sum=0;
while(n<=5)
{
cout<<n<<endl;
sum=sum+n;
n=n+1;
}
cout<<"sum is="<<sum;
getch();
}


OUTPUT

by gul ahmad · 0

write c++ program that display counting from 10 to 1


 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 
#include<iostream.h>
#include<conio.h>
void main(){
int n;
n=10;
while(n>=1)
{
cout<<n<<endl;
n=n-1;
}
getch();
} 
 

OUTPUT

by gul ahmad · 0

write c++ program that display counting from 1 to 10


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int n;
n=1;
while(n<=10)
{
cout<<n<<endl;
n=n+1;
}
getch();
}






OUTPUT

by gul ahmad · 0

write c++ program to input two number and find(print) greater number


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int a,b;
cout<<"enter first number=";
cin>>a;
cout<<"enter second number=";
cin>>b;
if(a>b)
cout<<"first number is greater";
else
cout<<"second number is greater";
getch();
}



OUTPUT

by gul ahmad · 0

Write a c++ program to find multiplication table of number


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int n,i;
i=1;
cout<<"Enter a number : ";
cin>>n;
while(i<=10)
{
cout<<n<<"*"<<i<<"="<<n*i<<endl;
i=i+1;
}
getch();
}


OUTPUT

by gul ahmad · 0

Write a c++ program to find out power of number.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
 
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int pow,num,i=1;
long int sum=1;
cout<<"\nEnter a number: ";
cin>>num;
cout<<"\nEnter power: ";
cin>>pow;
while(i<=pow){
sum=sum*num;
i++;
}
cout<<"the power of number is "<<sum;
getch();
}
        


OUTPUT


by gul ahmad · 0

Write a c++ program to get factorial of given number.



1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int i=1,f=1,num;
cout<<"enter a number=";
cin>>num;
while(i<=num){
f=f*i;
i++;
}
cout<<"factorial of "<<num<<"is"<<f;
getch();
}

OUTPUT

by gul ahmad · 0

Tuesday, 8 April 2014

C++ program to check a number is odd or even.


  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main(){
  4. int number;
  5. cout<<"enter any integer:";
  6. cin>>number;
  7. if(number % 2 ==0){
  8. cout<<"the number is even";
  9. }
  10. else{
  11. cout<<"the number is odd";
  12. }
  13. getch();
  14. }
OUTPUT

Tuesday, 8 April 2014 by gul ahmad · 0

Write a c++ program to check given number is prime number or not.


  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main(){
  4. clrscr();
  5. int num,i,count=0;
  6. cout<<"enter a number=";
  7. cin>>num;
  8. for(i=2;i<=num/2;i++){
  9. if(num%i==0){
  10. count++;
  11. break;
  12. }}
  13. if(count==0 && num!= 1){
  14. cout<<"the number is prime";
  15. }
  16. else{
  17. cout<<"the number is not prime";
  18. }
  19. getch();
  20. }
OUTPUT

 

by gul ahmad · 0

Write a c++ program to check given number is perfect number or not.

  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main(){
  4. clrscr();
  5. int n,i=1,sum=0;
  6. cout<<"enter a number=";
  7. cin>>n;
  8. while(i<n){
  9. if(n%i==0)
  10. sum=sum+i;
  11. i++;
  12. }
  13. if(sum==n){
  14. cout<<n<<"is perfect number";
  15. }
  16. else{
  17. cout<<n<<"is not perfect number";
  18. }
  19. getch(); 
  20. }
OUTPUT

 

by gul ahmad · 0

All Rights Reserved c++ programming