Squared

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”.

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
বাংলা স্টেটমেন্ট এ ক্ষেত্রফল না লিখে আয়তন লিখা।

1 Like

// 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?