help wid C-script in tcsh

Hello Freinds

I have just started off with Unix (TCSH) although I have a pretty sound background with C-programming. Kindly convey any error in foll script.

#include<stdio.h>
#include<math.h>
#define PI 3.142857
main ()
{
float r, A;
printf("Enter the value of radius: ");
scanf(" %f ",&r);
A = ((PI/4)*r*r);
printf("Area of circle is %f", A);
}

I can compile it with gcc but when I run it in terminal, it returns nothing, guess it goes into a loop.

Pls help

Hm, sense of deja vu with this one.

Make r and A doubles.

The printf format "%f" actually works with doubles, not floats.

Things may have changed since my days at school, but I thought that area was

PI*r*r

Does it just hang?

Circle - Wikipedia, the free encyclopedia

thanx porter

but still not working, even wid doubles.

it just hangs. I have to Ctrl-Z i.e. suspend it.

just a thought

include<stdio.h>
include<math.h>
define PI 3.142857
main ()
{
float r, A;
printf("Enter the value of radius: ");
scanf(" %f ",&r);
A = (PI/4)*(r*r);
printf("Area of circle is %f", A);
}

but its in C, so # is necessary at d beginning.

Just not able to get it runnin. Grrrr.....

#include<stdio.h>
#include<math.h>
main ()
{
const float PI=3.142857;
double r, A;
A = (PI/4)*(r*r);

cout<<"Enter the value of radius: ";
cin>>r;

cout<<"Area of circle is "<< A;
}

This works on Solaris using gcc.

#include<stdio.h>
#include<math.h>
#define PI 3.142857
int main(int argc,char **argv)
{
        float r, A;
        printf("Enter the value of radius: ");
        scanf("%f",&r);
        A = ((PI/4)*r*r);
        printf("Area of circle is %f", A);
        return 0;
}

even if I don't agree with the actual algorithm.

Note I changed the scanf to be purely "%f".

all: area

area: area.c
        $(CC) $(CFLAGS) -Wall -Werror area.c -o $@

EUREKA! THANX A LOT PORTER!
THOUGH I MIGHT NEED TO DELVE DEEPER INTO
'int main(int argc,char **argv)'
I SHALL READ ON IT FURTHER.
THANX AGAIN!:b:

Hm, because earlier you said

I didnt know that my 'pretty sound' was not dat pretty....

Hi Mahendra,

 The problem is that you should NOT put any space after the %f and before the "\) ur statement is like scanf\(" %f ", &r\); u put this line 

scanf("%f",&r); it will work fine.

Thanks.

Krishna,

How this space in scanf matters? Any more inputs?

Hm, like I mentioned back then...

sscanf would other wise be looking for a space before the number hence why if you just type a number it appears to hang because you have not provided the space.