in c++ language
1.Re-write the following for loop statement by using a while loop statement:
int sum = 0;
for(int i=0;i<=1000;i++){
sum+=i;
}
1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered.
int main()
{
int score, highest;
//missing portion of the program
return 0;
}
1(c). Find the missing portion of the following code, so the program will display a graph as following:
1: *
2: * *
3: * * *
4: * * * *
5: * * * * *
int i=1;
while(i<=5){
cout<<i<<": ";
//missing statement
cout<<endl;
i++;
}
1 (d). Write a do-while loop statement that displays “Good Morning!” 5 times.
1(e). Following is the main () function of a program. The program asks a user to enter an integer that is greater than or equal to 3, then list all the multiples of 3 that are less than or equal to that integer. For example, if the integer that a user entered was 16, then your program should print out following numbers: 3, 6, 9, 12, 15. Please complete the missing part of the main () function:
int main()
{
int n;
cout<<”Please enter an integer that is greater than or equal to 3: “;
cin>>n;
//missing portion of the program
return 0;
}
1(f). Write a statement or statements that displays the ACSII code of character ‘&’
1 ) while loop:
int sum=0;
int i=0;
while(i<=1000)
{
sum+=i;
i++;
}
1 b) Largest integer user entered
#include<iostream>
using namespace std;
int main()
{
int score, highest;
for(int i=1;i<=150;i++)
{
cout<<"Enter score"<<i<<": ";
cin>>score;
if(i==1)
{
highest=score;
}
if(highest<score)
{
highest=score;
}
}
cout<<"Largest integer user entered:
"<<highest<<endl;
return 0;
}
1 c) Display a graph:
#include<iostream>
using namespace std;
int main()
{
int i=1;
while(i<=5)
{
cout<<i<<": ";
for(int j=1;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
i++;
}
return 0;
}
1 d) Print "Good Morning!" 5 times using do...while loop
#include<iostream>
using namespace std;
int main()
{
int i=1;
do
{
cout<<i<<". Good Morning!"<<endl;
i++;
}while(i!=6);
return 0;
}
1(e): Multiples of 3
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Please enter an integer that is greater than or equal
to 3: ";
cin>>n;
if(n>=3)
{
cout<<"Multiples of 3: "<<endl;
for(int i=1;i<=n;i++)
{
if(i%3==0)
{
cout<<i<<"\t";
}
}
}
else
{
cout<<"Integer has to be greater or equal to 3!";
}
return 0;
}
1(f). Display the ASCII code of character '&':
#include<iostream>
using namespace std;
int main()
{
char ch;
ch='&';
cout<<"The ASCII code of '&' character is
"<<(int)ch<<endl;
return 0;
}
in c++ language 1.Re-write the following for loop statement by using a while loop statement: int...
Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;
C++ Program Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with a newline. Ex: For the user input 123, 395, 25, the expected output is: Enter a number (<100): Enter a number (<100): Enter a number (<100): Your number < 100 is: 25 #include <iostream> using namespace std; int main() { int userInput; /* Your solution goes here */...
Sum of Numbers: Write a program that asks the user for a positive integer value.The program should use a loop to get the sum of all the integers from 1 up to the number entered.For Example, if the user enters 50, the loop will find the sum of 1,2,3,4,…50.C++
// Finish the following program which adds up all integers from 0 to// the user's given number inclusively using a While Loop. The total should be// assigned to the variable 'total'.#includeusing namespace std;int main() {int number;int total = 0;int counter = 0; //initialize the variable// user enters a numbercout << "Enter a positive integer to find the summation of ";cout << "all numbers from 0 to the given number up to 100." << endl;cin >> number;// check for invalid user...
Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with a newline. Ex: For the user input 123, 395, 25, the expected output is: Enter a number (<100): Enter a number (<100): Enter a number (<100): Your number < 100 is: 25 c++ #include using namespace std; int main() { int userInput = 0; do cout << "Your number <...
the coding language is just the basic c language and here is my first attempt at this problem my problem is that if the user inputs a number that is equal to a number that has been entered previously the code will never end until the user enters a number that is bigger than any other number previously entered any help will be helpful Write a program to read-in a sequence of integers from the keyboard using scanf(). Your program...
Convert the following while loop into a for loop. int 1 - 50: int sum-07 while (sum < 1000) sum - sum + 1; Question 35 (2 points) Saved Given an int variable k that has already been declared, use a while loop to print a single line consisting of 80 dollar signs. Use no variables other than k. int sum = 0; for(int i = 100;sum < 10000;1-- sum = sum + i;
Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with userNum initially 9 and user input of 5, 2, -1, then with userNum initially 0 and user input of -17, then with userNum initially -1. See "How to Use zyBooks". . Also note: If the submitted code has an infinite loop, the system will...
Consider the following C++ program: #include <iostream> #include <cstdlib> using namespace std; int main int n =0; int i = 0; cout << "Please enter a strictly positive number:"; cin >> n if (n <= 0) exit(EXIT_FAILURE) while (n > 1) n-n/2; i << endl; cout"Output:" return 0; Answer the following questions: What is the output of the program for each of the following values of n: -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9? What does...
#include <iostream> using namespace std; int main() { int sumOdd = 0; // For accumulating odd numbers, init to 0 int sumEven = 0; // For accumulating even numbers, init to 0 int upperbound; // Sum from 1 to this upperbound // Prompt user for an upperbound cout << "Enter the upperbound: "; cin >> upperbound; // Use a loop to repeatedly add 1, 2, 3,..., up to upperbound int number =...