Squared

This is a companion discussion topic for the original entry at https://toph.co/p/squared

my outcome is right but why does the test in toph say wrong answer

``````#include<stdio.h>
int main()
{
float side,area;
scanf("%f",&side);
area=side * side;
printf("%f",area);
return 0;

}
``````

@AG_Ohe11 Try using `int` instead of `float`.

@AG_Ohe11 kire ohe naki?

i tested this program and it also work then why here its saying compilation wrongâĻ

``````#include <stdio.h>
#include<math.h>

int main()
{
int side,area;
scanf("%d",&side);
area=side*side;
printf("%d",area);

return 0;
}
``````

There is no problem with your code. The compiler compiled it successfully. So itâs not possible to get Compilation Error.

@hjr265
āĻŦāĻžāĻāĻ˛āĻž āĻ¸ā§āĻā§āĻāĻŽā§āĻ¨ā§āĻ āĻ āĻā§āĻˇā§āĻ¤ā§āĻ°āĻĢāĻ˛ āĻ¨āĻž āĻ˛āĻŋāĻā§ āĻā§āĻ¤āĻ¨ āĻ˛āĻŋāĻāĻžāĨ¤

2 Likes

// 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âĻ

#include<stdio.h>
int main()
{
int length,area;
area =length*length;
scanf("%d",&length);
printf("%d\n",area);
}
what is the problem with this code?

``````L = input(int())
sum = L ** 2
print (sum)
``````

what is the problem

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.

Hello Anonya Akand remmember me from BDJSO?