Write a program to find the average of two numbers.
#include<iostream.h>
#include<conio.h>
main ()
{
float num1, num2, sum, avg;
cout << "Enter two numbers :";
cin >> num1;
cin >> num2;
sum = num1+num2;
avg=sum/2;
cout << "Sum = " << sum << "\n";
cout << "Average = " << avg << "\n";
getch();
return 0;
}
OUTPUT:
Enter the two numbers: 2 2
Sum= 4
Average= 2
#include<iostream.h>
#include<conio.h>
main ()
{
float num1, num2, sum, avg;
cout << "Enter two numbers :";
cin >> num1;
cin >> num2;
sum = num1+num2;
avg=sum/2;
cout << "Sum = " << sum << "\n";
cout << "Average = " << avg << "\n";
getch();
return 0;
}
OUTPUT:
Enter the two numbers: 2 2
Sum= 4
Average= 2
No comments:
Post a Comment