Computer Science, asked by luna26, 16 hours ago

write a program in C to find the square of a number

Answers

Answered by MichMich0945
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