Given the length of a side of a square, calculate and print its area.
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
// you have to input integer and output integer…
#include<stdio.h>
#include<math.h>
int main()
{
int a;
scanf(“%d”,&a);
printf(“%d”,(int) pow(a,2) );
return 0;
}
//you can write a program like it though it’s so difficult for beginners…
The value of an integer after declaration is always 0, unless another value’s assigned to it. In your code, you’re assigning the value of 0*0 to the variable area in the 5th line. So, try assigning the value to area after taking the input.
In python, the only parameter of input() is prompt, which is a string to display before taking input. The function input() doesn’t allow anything else as parameters. Whereas, the function int() takes two arguments,
x - A string or a number, to be converted to an int object.
base - Base of the number in x.
You meant to convert the inputted string to an integer. So you have to change your code like int(input()). It’ll convert the string inputted by the user to an integer object.