Write a program segment using WHILE loop condition that writes the numbers 0 to
ID: 3698630 • Letter: W
Question
Write a program segment using WHILE loop condition that writes the numbers 0 to 30 with an increment of 6. Sample run: 1) 0 612 18 24 30 2) Write a program segment using WHILE loop condition that writes the numbers 50 to 0 with a decrement of 10. Sample run: 50 40 30 20 100 3) Write a program segment using WHILE loop condition that reads a number from the user and writes the series of numbers starting from 0 to that number. The input/output should be the following (note the user input is in bold). HINT: You will need a count variable. Please enter a number:8 012345678 Write a program segment using WHILE loop condition that reads a number from user and writes the series of numbers starting from that number until zero with the folowing text. Also, outputs the sum of those numbers. The input/output should be the following (note the user input is in bold): 4) Please enter a number: 6 The positive numbers are: 6543210 The sum of the above numbers is: 21Explanation / Answer
1) Program.
#include <iostream>
using namespace std;
int main()
{
for(int i=0;i<=30;i=i+6)
{
cout<<i<<" ";
}
}
2) program
#include <iostream>
using namespace std;
int main()
{
for(int i=50;i>=0;i=i-10)
{
cout<<i<<" ";
}
}
3) Program
#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"Please enter a number: "<<endl;
cin>>n;
for(int i=0;i<=n;i++)
{
cout<<i<<" ";
}
}
4) Program
#include <iostream>
using namespace std;
int main()
{
int n,sum=0;
cout<<"Please enter a number: "<<endl;
cin>>n;
cout<<"The positive number are: ";
for(int i=n;i>=0;i--)
{
sum=sum+i;
cout<<i<<" ";
}
cout<<endl;
cout<<"The sum of number is: "<<sum<<endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.