You are on page 1of 2

2021-2022 Spring Semester

Assoc. Prof. Dr. Ezgi Deniz Ülker


Due date:17.06.2022
at 17:00 (Cyprus time)

EUROPEAN UNIVERSITY OF LEFKE


Faculty of Engineering
COMP 117 / Computing Foundations
LAB STUDY 10

“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

Name: Mukunzi Ange Teta


Student number: 21143125
Department: computer engineering

IMPORTANT NOTICE:

**The file needs to be submitted as pdf file.


**No handwritten pdf files are accepted. Algorithms and flowcharts need to be prepared by using
word processing tools.
**Submissions can be ONLY done to the moodle page into the related field.
**No further submissions will be accepted, if the deadline is missed.
**Please know that if you are not enrolled to the moodle page of our course, you are not able to see
the link of submission.

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.)

The program will find and print the following;


a. Summation of the numbers.
b. Summation of negative numbers.
c. Average of all numbers.

For loop program

#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;
}

You might also like