Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to make the number come in decimal. send the revised code correctly

0 votes
asked May 19, 2021 by 5 G-16 Jain Bharggav Mukul (350 points)
#include<stdio.h>

int main()
{
    int a,c;
    
    
    printf("\n Enter radius: ");
    scanf("%d",&a);
    c=3.14*a*a;
    printf("radius is %d",c);
}

5 Answers

+2 votes
answered May 19, 2021 by Peter Minarik (86,240 points)
selected May 19, 2021 by 5 G-16 Jain Bharggav Mukul
 
Best answer
  • Decimal (floating point) numbers are stored as floats or doubles (double precision floating point numbers), not ints.
  • It's good idea to name your variable with a meaningful name. What is a or c?
  • Make sure you print the correct thing to the user and do not confuse him/her. (printf("radius is %d",c); says radius, but c is not the radius, rathe the area of the circle.)
  • I'd recommend looking at the documentation of printf to understand how to format your output.

Here's the fixed code.

#include <stdio.h>

int main()
{
    float radius;
    printf("Enter radius: ");
    scanf("%f",&radius);
    float area = 3.14 * radius * radius;
    printf("The area is %f\n", area);
    return 0;
}
0 votes
answered May 20, 2021 by LaurB Bw (140 points)

#include<stdio.h>

int main()
{
    Float a,c;  //put float or double
    
    
    printf("\n Enter radius: ");
    scanf("%d",&a);
    c=3.14*a*a;
    printf("radius is %d",c);
}

0 votes
answered May 24, 2021 by Shailesh Khanvilkar (140 points)
#include<stdio.h>

#include<conio.h>

int main()

{

int radius;

float area;

printf("enter the radius");

scan("%d",&radius);

area=3.14*radius*radius;

printf("the area is %.3f",area);

return 0:

}
0 votes
answered May 24, 2021 by Bhushan Sngh (140 points)

use float intead of integer.

#include<stdio.h>

int main()
{
    float a,c;
    
    
    printf("\n Enter radius: ");
    scanf("%f",&a);
    c=3.14*a*a;
    printf("radius is %f",c);
}

–1 vote
answered May 31, 2021 by bikash123-c (270 points)
#include<stdio.h>
#include<conio.h>
 int main()
 {
  float r=10,area, circum,PI=3.1214;
  area = PI * r * r;
  circum = 2* PI *  r;
  printf(" The area and the circumference of the circle are %f and %f respctively .",area,circum );
     
     
     return 0;
 }
commented Jun 1, 2021 by Peter Minarik (86,240 points)
If you post your solution, you should be in line with the original poster's goals. For instance, reading the radius from the user.

Also, getting the value of Pi wrong... (https://en.wikipedia.org/wiki/Pi)

You should pay more attention to the correctness of what you post, otherwise your post won't be helpful. :(
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...