0% found this document useful (0 votes)
32 views8 pages

1.WAP To Find Average of N Numbers.: Output

The document contains code snippets for 8 programs that perform basic calculations and operations: 1) calculating the average of numbers, 2) calculating simple interest, 3) swapping values of two variables using a third variable and without a third variable, 4) checking if a number is even or odd, 5) summing the digits of a number, 6) reversing the digits of a number. Each code snippet is followed by sample input/output demonstrating its functionality.

Uploaded by

Poonam Rana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views8 pages

1.WAP To Find Average of N Numbers.: Output

The document contains code snippets for 8 programs that perform basic calculations and operations: 1) calculating the average of numbers, 2) calculating simple interest, 3) swapping values of two variables using a third variable and without a third variable, 4) checking if a number is even or odd, 5) summing the digits of a number, 6) reversing the digits of a number. Each code snippet is followed by sample input/output demonstrating its functionality.

Uploaded by

Poonam Rana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1.WAP to find average of n numbers.

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int i,a[30],n;
float avg,sum=0;
cout<<"\n Enter the number of elements whose average is to be found ";
cin>>n;
cout<<"\n Enter the numbers ";
for(i=0;i<n;i++)
{ cin>>a[i];
sum=sum+a[i];
}
avg=sum/n;
cout<<"\n Average = "<<avg;

OUTPUT :
Enter the number of elements whose average is to be found : 5
Enter the numbers 3 7 4 9 10
Average = 6.6

2. WAP to calculate simple interest .


#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
float p,r,t,s;
cout<<"\n Enter principle amount ";
cin>>p;
cout<<"\n Enter rate of interest per annum ";
cin>>r;
cout<<"\n Enter time in years ";
cin>>t;
s=(p*r*t)/100;
cout<<"\n Simple Interest = "<<s;

OUTPUT :
Enter principle amount in Rs.: 1200
Enter rate of interest per annum: 5
Enter time in years: 3
Simple Interest = Rs. 180

3. WAP to swap the value of two variables .


(1) Using 3rd variable :
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
float a,b,t;
cout<<"\n Enter two numbers: ";
cin>>a>>b;
cout<<"\n Value of a and b : "<<a<<" "<<b;
t=a;
a=b;
b=t;
cout<<"\n Swapped values of a and b : "<<a<<" "<<b;

OUTPUT:
Enter two numbers : 4 7
Value of a and b : 4 7
Swapped values of a and b : 7 4

(2) Without using 3rd variable :

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
float a,b,t;
cout<<"\n Enter two numbers: ";
cin>>a>>b;
cout<<"\n Value of a and b : "<<a<<" "<<b;
a=a+b;
b=a-b;
a=a-b;
cout<<"\n Swapped values of a and b : "<<a<<" "<<b;

OUTPUT:
Enter two numbers : 3 7
Value of a and b : 3 7
Swapped values of a and b : 7 3

5. WAP to check whether a no is even or odd.

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int a;
cout<<"\n Enter a number: ";
cin>>a;
if(a%2==0)
{
cout<<"\n Number is even " ;
}
else
{
cout<<"\n Entered number is odd " ;
}
}

OUTPUT:
Enter a number: 7
Entered number is odd

7. WAP to sum the digits of a number.


#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int n,p,sum=0;
cout<<"\n Enter a number: ";
cin>>n;
while(n!=0)
{
p=n%10 ;
sum=sum+p;
n=n/10;
}
cout<<" Sum of digits = "<<sum;
}
OUTPUT:
Enter a number: 1234
Sum of digits = 10

8. WAP to reverse the digits of a number.

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int n,p,rev=0;
cout<<"\n Enter a number: ";
cin>>n;
while(n!=0)
{
p=n%10 ;
rev=rev*10+p;
n=n/10;
}
cout<<" Reverse = "<<rev;
}

OUTPUT:
Enter a number: 1234
Reverse = 4321

You might also like