211k views
5 votes
Write a program that squares an integer and prints the result

A) int x = 5; printf("%d", x*x);
B) int x = 5; printf("%d", x²);
C) int x = 5; printf("%d", x**2);
D) int x = 5; printf("%d", square(x));

User Auzias
by
7.0k points

1 Answer

0 votes

Final answer:

The correct option for squaring an integer and printing the result is option A, which multiplies the integer by itself using the x*x syntax and prints the result using a printf statement.

Step-by-step explanation:

The correct option for writing a program that squares an integer and prints the result is option A.

This code initializes an integer variable x with the value 5. It then uses the printf function to print the square of x by multiplying it with itself (x*x). The %d format specifier is used to display the result as an integer.

User Qun Qin
by
7.5k points