1.WAP To Find Average of N Numbers.: Output
1.WAP To Find Average of N Numbers.: Output
#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
OUTPUT :
Enter principle amount in Rs.: 1200
Enter rate of interest per annum: 5
Enter time in years: 3
Simple Interest = Rs. 180
OUTPUT:
Enter two numbers : 4 7
Value of a and b : 4 7
Swapped values of a and b : 7 4
#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
#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
#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