[go: up one dir, main page]

0% found this document useful (0 votes)
112 views3 pages

Feu-It CCS Department Computer Programming 1 - Machine Problem

The document provides 3 programming problems to practice different repetition control structures in C++. The first problem uses a while loop to output all numbers from 1 to a user-input number. The second uses a do-while loop to output numbers increasing by 5 from 5 to 50. The third uses a for loop to calculate and output the sum of all numbers from 1 to a user-input number.

Uploaded by

Allysa Casison
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)
112 views3 pages

Feu-It CCS Department Computer Programming 1 - Machine Problem

The document provides 3 programming problems to practice different repetition control structures in C++. The first problem uses a while loop to output all numbers from 1 to a user-input number. The second uses a do-while loop to output numbers increasing by 5 from 5 to 50. The third uses a for loop to calculate and output the sum of all numbers from 1 to a user-input number.

Uploaded by

Allysa Casison
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/ 3

FEU-IT

CCS Department Computer Programming 1 – Machine Problem

Name: Date Performed: __________________

Course/Yr: Date Submitted: __________________

MP # 5

Using different repetition control structures


1. Using while loop, write a program that will ask the user for a positive integer number. Display all numbers from
1 to the user’s input. Consider the sample output.
Enter a number: 10
1 2 3 4 5 6 7 8 9 10

#include <iostream>

using namespace std;

main (){

int num, i;

cout<<"Enter a number:";

cin>>num;

i=1;

while (num>=i){

cout<<i<<"\n";

i++;
}
return 0;
}
FEU-IT
CCS Department Computer Programming 1 – Machine Problem

2. Using do-while loop, create a program that will display the following output
Output:
5 10 15 20 25 30 35 40 45 50

#include <iostream>

using namespace std;

int main()

int x = 5;

do{

cout <<x<<endl;

x = x + 5;

}while(x<55);

}
FEU-IT
CCS Department Computer Programming 1 – Machine Problem

3. Using, for loop, write a program that will ask the user for a positive integer number. Display the
sum of all numbers from 1 to the user’s input. Consider the sample output.
Enter a number: 10
Sum of all numbers from 1 to 10: 55

#include <iostream>
using namespace std;

int main()
{
int x, sum = 0;

cout << "Enter a number: ";


cin >> n;

for (int x = 1; x <= n; ++x) {


sum += x;
}

cout<< "Sum of all numbers : "<<sum;


return 0;
}

You might also like