0% found this document useful (0 votes)
143 views3 pages

Wap in C++ To Add Two Numbers

The document contains 6 C++ programs: 1) A program to add two numbers by taking input from the user and displaying the sum. 2) A program to swap two numbers by taking input from the user and displaying the swapped numbers. 3) A program to check if a number entered by the user is even or odd. 4) A program to check if a number entered by the user is divisible by 5 or not. 5) A program to calculate the sum of first n natural numbers by taking n as input from the user. 6) A program to calculate the sum of squares of first n natural numbers by taking n as input from the user.

Uploaded by

neela94
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
143 views3 pages

Wap in C++ To Add Two Numbers

The document contains 6 C++ programs: 1) A program to add two numbers by taking input from the user and displaying the sum. 2) A program to swap two numbers by taking input from the user and displaying the swapped numbers. 3) A program to check if a number entered by the user is even or odd. 4) A program to check if a number entered by the user is divisible by 5 or not. 5) A program to calculate the sum of first n natural numbers by taking n as input from the user. 6) A program to calculate the sum of squares of first n natural numbers by taking n as input from the user.

Uploaded by

neela94
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. WAP IN C++ TO ADD TWO NUMBERS.

#include<iostream.h>
//add two numbers
void main()
{
int a,b,s;
cout<<ENTER FIRST NUMBERS<<ENDL;
cin>>a;
cout<<ENTER SECONDNUMBERS<<ENDL;
cin>>b;
s=a+b;
cout<<THE SUM IS<<s<<endl;
getch();
}

2. WAP IN C++ TO SWAP TWO NUMBERS,


#include<iostream.h>
//swapping two numbers
void main()
{
int a,b,t;
cout<<ENTER FIRST NUMBER<<ENDL;
cin>>a;
cout<<ENTER SECONDNUMBER<<ENDL;
t=a;
a=b;
b=t;
cout<<AFTER EXCHANGE<<endl;
cout<<ENTER FIRST NUMBERS<<a<<ENDL;
cout<<ENTER SECONDNUMBERS<<b<<ENDL;
getch();
}
3. WAP TO CHECK A NUMBER IS EVEN OR ODD.
#include<iostream.h>
//TO CHECK A NO EVEN OR ODD
Void main ()
{
int a,r;
cout<<ENTER THE NUMBER<<ENDL;

cin>>a;
r=a%2;
if (a= = 0)
cout << THE NUMBER IS EVEN<<endl;
else
cout << THE NUMBER IS ODD<<endl;
getch();
}
4. WAP TO CHECK A NUMBER IS DIVISIBLE BY 5 OR NOT
#include<iostream.h>
//TO CHECK A DIVISIBLE BY 5 OR NOT
Void main ()
{
int a,r;
cout<<ENTER THE NUMBER<<ENDL;
cin>>a;
r=a%5;
if (a= = 0)
cout << THE NUMBER IS divisible by 5<<endl;
else
cout << THE NUMBER IS not divisible by 5<<endl;
getch();
}
5. WAP TO FIND THE SUM OF N NATURAL NUMBERS
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,sum=0;
cout<<"How many numbers? ";
cin>>n;
for(i=1;i<=n;++i)
{
sum+=i;
cout<<"\nSUM="<<sum<<endl;
}
getch();
}
6. WAP TO FIND THE SUM OF SQUARE OF N NATURAL NUMBERS
#include<iostream.h>
#include<conio.h>
#include<math.h>

void main()
{
clrscr();
unsigned long n,i,sum=0,d;
cout<<"Enter any number";
cin>>n;
for(i=1;i<=n;++i)
{
d=pow(i,i);
sum+=d;
}
++sum;
cout <<"Sum= "<<sum<<endl;
getch();
}

You might also like