Programing in C

Just wanted to share my accomplishment!
Some may think this is nothing, but I am excited!! For the past several hours I have been playing with the C programming language. This is for school but if anyone has suggestions, tips, or general educational help while I finish up this semester I am all ears!


Below is a program which will give you the area of a circle

#include

int main()
{
int r;
double pi;
pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286;

printf( "Please enter the radius: " );
scanf( "%d", &r );
printf( "You entered %din as your radious\r\n", r );
double area = r * r * pi;
printf ("The area of your circle is %fin\r\n", area);
printf ("Hit enter to end program.\r\n");
getchar();
getchar();
return 0;
}

Comments

  • 4 Comments sorted by Votes Date Added
  • I updated the code with a float r instead of int r which now allows for decimal places such as 4.7inches. Also placed a repeater in it for multiple area calculations instead of having to open the program every time a calculation is warranted.

    Sorry, I know this is a LEGO forum but I have been doing this ALL day and wanted to share my boring code to those who get this. :p



    #include

    int main()
    {
    float r;
    double pi;
    pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286;

    do {
    printf( "Enter Radius (ZERO to quit): " );
    scanf( "%f", &r );
    if ( r <= 0) {
    return 1;
    }
    double area = r * r * pi;
    printf ("The area of your circle is %fin\r\n", area);
    }while ( r > 0 );
    return 0;
    getchar();
    getchar();
    return 0;

    }

  • Lol, good job. Learning to program was a fun adventure so can't blame ya for posting that on a lego forum. It's exciting!
  • Cool budgetkids. :) Feel free to ask if you have C questions, you could say it's my native language.
  • Lol love it...

    ... realised i cant read c programming...

    ...who cares
Sign In or Register to comment.