Printf function is not running after the scanf method

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 you run it, the printf function after the scanf is not executed, what is wrong?

    
asked by anonymous 29.04.2018 / 16:35

4 answers

0

The correct scanf line is as follows: "scanf ("% d ", & radius);" You missed the & amp ;, so it does not continue to run, whenever it is to read a number should appear it in the front

    
29.04.2018 / 16:48
0

As already mentioned before, in order for the program to 'run' without errors, you need to put the '&' no scanf. Ex: scanf ("% d", & variableName);
Another observation refers to the output of the variable.
% d or% i = integers (no decimal places).
% f = Values to 6 decimal places Ex: 35.123456. To control the amount of houses you have two options:
1st within% f, you put the desired precision, suppose you need a value with two decimal precision precision:
printf ("my value:% .2f", myVariavel);
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, it automatically sets the output.

#include <stdio.h>  

const float PI = 3.14;
int main () {
   float ray

   double area;

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

area = PI * (radius * radius);

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

    
19.05.2018 / 22:59
-1

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

Your scanf will look like this:

scanf("%f", &radius);

That's all =)

    
29.04.2018 / 16:51
-2

Try to use fflush(stdin); before scanf , this command will clear the input buffer, it happens to scanf recognize the \n you previously used in printf as the enter of the value insertion but the variable is given an empty value.

    
29.04.2018 / 16:50