Professional Documents
Culture Documents
“This assignment that has been submitted by myself is solely my own work
and I did not get any aid from other people.”
**PLEASE WRITE YOUR NAME HERE
IMPORTANT NOTICE:
Write a C program that will ask the user to enter 10 integer numbers from the keyboard.
Write this program using;
i. FOR LOOP and ii. WHILE LOOP.
(There will be 2 different programs.)
#include <iostream>
using namespace std;
int main() {
int sum=0, i;
float avg , y;
cout << "Enter 10 elements one by one\n\n";
for(i = 0; i < 10; i++) {
cin >> y;
sum=sum+y; }
cout<<"the sum is"<<sum<<endl;
avg=sum/10;
cout << "\nThe average of the entered input numbers is = " << avg;
return 0;
}
While loop
#include <iostream>
using namespace std;
int main() {
int sum=0, i;
float avg , y;
cout << "Enter 10 elements one by one\n\n";
while (i < 10) {
cin >> y;
sum=sum+y;
i++;
}
cout<<"the sum is"<<sum<<endl;
avg=sum/10;
cout << "\nThe average of the entered input numbers is = " << avg;
return 0;
}