Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete program that declares an integer variable reads a value from th

ID: 3793728 • Letter: W

Question

Write a complete program that declares an integer variable reads a value from the keyboard into that variable, and writes to standard output the square of the variable's value Besides the number, nothing else should be written to standard output Note that, in this context, "read" means input and "write" means output. To see how to calculate the square of a number, see the lecture slide packet named "Constants Lesson, " slide #8, and the lecture slide packet titled "Arithmetic Expressions Lesson #1, " slides 8-9. To see how to output the value of an arithmetic expression, see the lecture slide packet titled "Arithmetic Expressions Lesson #2, " slide 21.

Explanation / Answer

#include <stdio.h>

int main()
{
int value;
printf("Enter the value: ");
scanf("%d", &value);
value = value * value;
printf("%d ", value);

return 0;
}

Output:

sh-4.2$ gcc -o main *.c                                                                                                                                                                                                                                               

sh-4.2$ main                                                                                                                                                                                                                                                           

Enter the value: 4                                                                                                                                                                                                                                                     

16

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote