scanf - C does not run until I use the quit command -


fellow programmers. pretty new area why may having problem.

i told write program finds area , circumference of circle. 1 condition, display output 5 decimal places. output should this.

the radius of circle ________.

the diameter of circle is_______.

the area of circle is__________.

the circumference is____________.

here code wrote problem.

#include<stdio.h>     int main()     {         float r, area, circ, diam, pi = 3.14159;          printf("enter radius please");         scanf("%f\n", &r);          printf("the radius of circle %0.5f\n", r);          diam = 2 * r;         printf("the diameter of circle %0.5f\n", diam);          area = pi * r * r;         printf("the area of circle %0.5f\n", area);          circ = 2 * pi * r;         printf("the circumference of circle %0.5f\n", circ);          return 0;     } 

the code runs , showing me in terminal

enter radius please4 

i placed 4 testing sample. when program stops working. type q , hit enter. when rest of output shows so.

the radius of circle 4.00000 diameter of circle 8.00000 area of circle 50.26544 circumference of circle 25.13272 

najik, sure want have "\n" in scanf ? think want need remove it. before:

scanf("%f\n", &r); 

after:

scanf("%f", &r); 

this ensure scanf function finished shortly after entering number , pressing enter.

hope had you.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -