write a program in C to find the square of a number
Answers
Answered by
1
Program:
// C program to find the square of a number.
#include <stdio.h>
int main()
{
// Declare the required variables.
int num, is_valid, s;
// Ask the user to enter a number.
printf("Enter number: ");
is_valid = scanf("%d", &num);
if (is_valid != 0)
{
// Calculate the square by multiplying the number by itself.
// i.e num x num | 2^2 = 2*2=4
s = num * num;
// Print the result to the console/output.
printf("Square of %d is %d.\n", num, s);
}
else
{
// Else print error.
puts("Please enter a valid number!");
}
return 0;
}
Output: provided in the attachment...
Hope this helps you!
Attachments:
Similar questions
English,
8 hours ago
Accountancy,
8 hours ago
Math,
8 hours ago
Chemistry,
16 hours ago
History,
16 hours ago
Computer Science,
8 months ago
Physics,
8 months ago