Question

In: Computer Science

(C++) Write a program that prints a table in the following format given a "x" read...

(C++)

Write a program that prints a table in the following format given a "x" read from the keyboard. For example, if x is 4, it prints out

0 0

1 1

2 4

3 9

4 16

To avoid mismatch, put 8 white spaces between two numbers.

Solutions

Expert Solution

Below is the c++ program which takes an integer x and displays the output as mentioned above - (after the code, attached the sample output images of random input tests) -

#include <iostream>
using namespace std;
int main() 
{
   int x;
   cout<<"Enter x: ";
   cin>>x;
   cout<<endl;
   for(int i=0;i<=x;i++)
   {
       cout<<i<<"        "<<i*i<<endl;
   }
   
   return 0;
}

Code image :

Output sample-1 :

Sample output-2 :


Related Solutions

Write a menu driven C++ program that prints the day number of the year , given...
Write a menu driven C++ program that prints the day number of the year , given the date in the form of month-day-year. For example , if the input is 1-1-2006 , then the day number is 1. If the input is 12-25- 2006 , the day number is 359. The program should check for a leap year. A year is leap if it is divisible by 4 but not divisible by 100. For example , 1992 , and 2008...
Write a C++ program that prints a calendar for a given year. ONLY USING "#include<iostream>" and...
Write a C++ program that prints a calendar for a given year. ONLY USING "#include<iostream>" and "#include<cmath>" The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:       0 Sunday                     1 Monday                   2 Tuesday                   3 Wednesday       4 Thursday                 5 Friday                      6 Saturday Your program should...
Write a C program that, given a file named Program_2.dat as input, determines and prints the...
Write a C program that, given a file named Program_2.dat as input, determines and prints the following information: The number of characters in the file. The number of uppercase letters in the file. The number of lowercase letters in the file. The number of words in the file. The number of lines in the file. Your program should assume that the input file, Program_2.dat, may contain any text whatsoever, and that text might be, or might not be, the excerpt...
Write a C program, char.c, which prints the numerical value of the special character constants given...
Write a C program, char.c, which prints the numerical value of the special character constants given below. Don’t just look up the codes and print them directly from your program. You should have your program output the values of the character constants by using them as string literals within your printf() statements. Your output should be presented in a neat, orderly, tabular format as shown below: Char Constant Description Value '\n' newline '\t' horizontal tab '\v' vertical tab '\b' backspace...
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
Write a program that generates and prints out in a neat format all possible truth tables...
Write a program that generates and prints out in a neat format all possible truth tables with three propositional variables p, q, and r. Your program should also number generated truth tables and output the numbers so it is clear how many total tables were generated. Your program output may look like the following (Note: only the beginning of the output is shown): Truth table 1: p q r proposition ----------------- F F F F F F T F F...
Write a program that uses a while statement to read integers from the user and prints...
Write a program that uses a while statement to read integers from the user and prints the sum, average, and largest of these numbers. The input should terminate if the user enters 999. The average should be output with 4 digits of precision. c++ please ASAP
C program, please Write a program that reads a sequence of 10 integer inputs and prints...
C program, please Write a program that reads a sequence of 10 integer inputs and prints the smallest and largest of the inputs and the number of even and odd inputs. for a beginner please, you could use a while loop,if-else,
Write a C++ program that prints the insurance fee to pay for apet according to...
Write a C++ program that prints the insurance fee to pay for a pet according to the following rules:(NOTE:You must use a switch statement to determine pet fee.)A dog that has been neutered costs $50.A dog that has not been neutered costs $80.A cat that has been spayedcosts $40.A cat that has not been spayedcosts $60.A bird or reptile costs nothing.Any other animal generates an error message.The program should prompt the user for the appropriate information: a character code for...
in C++ programing language Write a program that prompts the user for an integer, then prints...
in C++ programing language Write a program that prompts the user for an integer, then prints all of the numbers from one to that integer, separated by spaces. Use a loop to print the numbers. But for multiples of three, print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Drop to a new line after printing each 20 numbers. If the user typed...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT