So I tried to write a program to tell me the circumference and area of a circle when I input the radius but it don't want to work ( I am following instructions from a book (Beginning C by Ivor Horton's)) so here is the program ;
#include <stdio.h>
void main()
{
float radius= 0.0f;
float circu= 0.0f;
float area= 0.0f;
float PI= 3.14159f;
printf("Input the radius of the circle:");
scanf("%f" , &radius);
circu = 2.0f * PI * radius;
area= PI*radius*radius;
printf("\nThe circonferance is %f" , circu);
printf("\nThe area is %f" , area);
}
CodePudding user response:
seem that works good
gcc t.c -Wall
t.c:3:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
3 | void main()
| ^~~~
a@zalman:~/Dokumenty/temp$ ./a.out
Input the radius of the circle:2.0
The circonferance is 12.566360
The area is 12.566360
CodePudding user response:
The Programm seems to work pretty well. If you have Problems with
scanf()
Then try fflush(stdin); Before executing scanf(). It clears stdin and stops a bug, where a scanf() doesnt clear a NEWLINE(\n) and the next scanf() just reads the NEWLINE so it doesnt have any normal input