Question

1 #include<iostream> 2 using namespace std; int main() int number; 7 cout < Enter a number to p cin number; cout << start: rint the square numbers in reverse order from numb 10 ut << 1. N was: number return e; 12 13


media%2F8f6%2F8f6e185f-adef-47e6-83dd-08


media%2Fb44%2Fb44af6b8-0e16-483e-81de-26


0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include <iostream>

using namespace std;

int main() {

int number,i;

cout<<"Enter a number to print the square numbers in reverse order from number: "<<endl;

cin>>number; // Here we are taking user Input

cout<<"start:";

if(number>=0) // Here we are checking if the user input is positive number

{

for(i=number;i>0;i--)

{

cout<<i*i<<","; // Here we are Printing Squares in decreasing order

}

}

else if(number<=0) // Here we are checking if the user input is negative number

{

for(i=number;i<0;i++)

{

cout<<i*i<<",";// Here we are Printing Squares in decreasing order

}

}

cout<<" N was: "<<number;

return 0;

}

Output:

Enter a number to print the square numbers in reverse order from number:
start:81,64,49,36,25,16,9,4,1, N was: 9

Output: // if user input is negative number

Enter a number to print the square numbers in reverse order from number:
start:9,4,1, N was: -3

Add a comment
Know the answer?
Add Answer to:
1 #include<iostream> 2 using namespace std; int main() int number; 7 cout < "Enter a number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout...

    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;

  • #include <iostream> using namespace std; int main(void) {    int SIZE;    cout<<"Enter the size of the...

    #include <iostream> using namespace std; int main(void) {    int SIZE;    cout<<"Enter the size of the array"<<endl;    cin>>SIZE;     int *numlist = new int[SIZE];     // Read SIZE integers from the keyboard     for (int i = 0; i<SIZE; i++ )    {        cout << "Enter value #" << i+1 << ": ";        cin >> numlist[i];     }     // Display the numbers in a reverse order     for (int i = SIZE; i > 0; i--...

  • Write the missing statements for the following program. #include <iostream> using namespace std; int main(void) {...

    Write the missing statements for the following program. #include <iostream> using namespace std; int main(void) { int Num1; cout << "Enter 2 numbers: ";    cin >> Num2; if (Num1 < Num2) cout << "Smallest number is " << Num1; else cout << "Smallest number is " << Num2;    return 0; }

  • #include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0;...

    #include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0; while(true) { cout << "Please enter a number between 1 and 11: "; cin >> number; if (number >= 1 && number <= 11) { cout << number << endl; sum = sum + number; //only add the sum when number is in range: 1-11, so add wthin this if case } else { cout << number << endl; cout << "Out of range;...

  • #include <iostream> uisng  namespace std; int main() {             cout<<"Enter your three test scores and I...

    #include <iostream> uisng  namespace std; int main() {             cout<<"Enter your three test scores and I will ";                  <<" average them: ";             int score1, score2, score3,             cin>>score1>>score2>>score3;             double average;             average = (score1 + score2 + score3) / 3.0;             if (average = 100);                         perfectScore = true; // set the flag variable             cout<<"Your average is "<<average <<endl;             bool perfectScore;             if (perfectScore);             {                         cout<<"Congratulations!\n";                         cout<<"That's a perfect score.\n";                        ...

  • #include <iostream> using namespace std; int main() {    int sumOdd = 0; // For accumulating...

    #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 =...

  • #include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0));...

    #include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0)); int number, guess, response, reply; int score = 0 number = rand() % 100 + 1; do { do { cout << "Enter your guess "; cin >> guess; score++; if (guess < number) cout << guess << " is too low! Enter a higher number. "; else if (guess > number) cout << guess << " is too high! Enter a lower number....

  • Fix this code so only the function prototype comes before main. #include <iostream> using namespace std;...

    Fix this code so only the function prototype comes before main. #include <iostream> using namespace std; bool isMultiple(int num1, int num2) { return num1 % num2 == 0; } int main() { char ch = 'Y'; int num1, num2; while(ch =='Y') // While ch is equal to Y { cout << "Enter two numbers(largest first): "; cin >> num1; // Getting 1st number cin >> num2; // Getting 2nd number if(isMultiple(num1, num2)) cout << num2 << " " << "IS...

  • One dimensional array What this code print #include <iostream> using namespace std; int main () {...

    One dimensional array What this code print #include <iostream> using namespace std; int main () { const int SIZE = 7; int numbers [SIZE] = {1, 2, 4, 8): // Initialize first 4 elements cout << “Here are the contents of the array:\n"; for (int index = 0; index < SIZE: index++} cout << numbers[index] << “ “; cout << endl; return 0; }

  • Add comments on this Fibonacci C++ program in detail. #include <iostream> using namespace std; int fib(int...

    Add comments on this Fibonacci C++ program in detail. #include <iostream> using namespace std; int fib(int n){ int a = 0,b = 1,c; if(n == 0 || n == 1){ return n; } while(n>2){ c = b + a; a = b; b = c; n--; } return c; } int main(){ int n; cout<<"Enter n: "; cin>>n; int result = fib(n); cout<<"Fib("<<n<<") = "<<result<<endl; return 0; }

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT