printf function is not running after scanf method

Asked

Viewed 158 times

0

Well my problem is this, I have a program that calculates the area of a circle, here’s the code:

#include <stdio.h>

#define PI 3.14

int main()
{
   double radius;
   double area;

   printf("Program to calculate the are of a circle\n");
   printf("Enter the radius: ");
   scanf("%d", radius);

   area = (radius * radius) * PI;

   printf("The area is: %d", area);

   return 0;
}

But when running it, the printf function after scanf is not executed, which is wrong?

4 answers

0


Correct on the scanf line is as follows: "scanf("%d", &Radius);" Missed the &, so it does not continue the execution, whenever it is performing the reading of a number it should appear in front

0

As has been said before, for the program to run error-free, you need to put the "&" in the scanf.
Ex: scanf("%d", & nameVariable);
Another observation refers to the output of the variable.
%d or %i = whole numbers (without decimal place accuracy).
%f = Values accurate to 6 decimal places Ex: 35.123456.
To control the amount of houses you have two options:
1º within %f, Voce puts the desired precision, suppose Voce needs a value with precision of two decimal places:
printf(" my value: %.2f", myVariable);
the balcony is between '%' and 'f', put '.' and the number of houses: '.1' , '.2', ...
2nd you do as in the example below and use %g, this automatically configures the output.

#include <stdio.h>  

constfloat PI = 3.14;
int main(){
float radius;
double area;

printf("Program to chalk the area of a circle. n");
printf("Enter the lightning: ");
scanf("%f", & radius);

area = PI * (radius * radius);

printf("Area = %g n",);
}

-1

First, it transforms all variables into float and puts a & in the scanf (When you see pointers you will understand why this)

Your scanf will stay like this:

scanf("%f", &radius);

That’s all =)

-2

Try to use fflush(stdin); before the scanf, this command will clear the input buffer, happens from scanf recognize the \n that you previously used on printf as the enter of the value but the variable receives an empty value.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.