Can Any Experts Help With This?

This is a discussion on Can Any Experts Help With This? within the C Programming forums, part of the General Programming Boards category; Code: hi. 1st of all i'm very sorry with my english.i'm not very fluent in it. I have a presentation ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    3

    Unhappy Can Any Experts Help With This?

    Code:
    hi.
    1st of all i'm very sorry with my english.i'm not very fluent in it.
    I have a presentation about c programming due next Monday, 16.Feb.2009
    The presentation is quite easy.I need to explain every line of the programme which i will write below.FYI,i took it from a C programming book.I already make some homework about the explanation but i think it is not enough..can someone recheck it for me..maybe add something useful or make it more clearer.Really need help here.
    
    Convert Radians to Degree
    
    1.   #include <stdio.h>
    2.   #define DEGREE_FACTOR 57.295779
    
    3.   int main (void)
    
    4.  {
    
    5.   double radians;
    6.   double degree;
    
    7.   printf ("Enter the angle in radians:");
    8.   scanf ("%lf", &radians);
    
    9.   degree = radians*DEGREE_FACTOR;
    10. printf ("%6.3f radians is %6.3f degree\n", radians, degree);
    
    11. return 0;
    12. }
    
    
    The Explanation
    
    1. Handle for input and output.
    2. Macro defination that define degree factor which is 57.295
    3. The main function or the body program indicates interger data type. (void)? can someone explain it?
    4. Begginning of the program.
    5. Variable which is radians.Double radians means it is from floating-point    
        variables.
    6.Variable which is degree.Double degree means it is from floating-point    
       variables.
    7.Output statement function.Can sumeone add more 
       explanation?
    8.Input statement function.using format specifier float because using float data   
       type, and address to radians in the memory location.Can someone explain it more.Any 1 more thing,what is lf? i know f is for float,but l ?
    9.The result,degree is stored in memory location.A mathematical calculation.
    10. Output function which is %f will be replace by answer, and radians and  
        degree will be locate in memory location for area.\n is for line spacing.Can someone explain why there is 6.3f radians and 6.3f degree?.I really dont know
    11. Return to OS to take over.
    12. End of program.
    
    
    I have red highlighted my major questions that i have been confiused and blured.Anyone also can add more explanation that will help improve my presentation.I hope u can help me.I really need help here A.S.A.P..Thanks~

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Part of your translation does not make sense, but someone else may be able to intuit more.

    In the context of printf, lf would refer to datatype double. (On my system it's hard to see the point, since while one occupies twice as many bytes as the other, the precision on both of them craps out at the same point:
    Code:
    include <stdio.h>
    
    int main() {
    	float y=13000000.3453f;
    	double x=13000000.3453f;
    	printf("float is %d bytes\ndouble is %d bytes\n",sizeof(float),sizeof(double));
    	printf("y is %f, x is %lf\n",y,x);
    	return 0;
    }
    float is 4 bytes
    double is 8 bytes
    y is 13000000.000000, x is 13000000.000000
    )
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,182
    (void) means it doesn't take any parameters.

    lf stands for long float, aka double.

    "%6.3f" means you want the field width to be 6 chars, 3 of them after the decimal place.
    Something like
    xx.xxx (decimal counts as a char in the field)

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    3
    Oic..
    thanks to both of u.
    Any extra explanation that can help me to give better presentation from others?.
    Actually i do research based on book from senior.Just the old one because its hard to get a really good book here.Many of programming books in the library is only C++ or VB..

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    Quote Originally Posted by xairzx View Post
    Code:
    Convert Radians to Degree
    
    1.   #include <stdio.h>
    2.   #define DEGREE_FACTOR 57.295779
    
    3.   int main()
    4.  {
    5.       double radians;
    6.       double degree;
    7.       printf("Enter the angle in radians:");
    8.       scanf("%lf", &radians);
    9.       degree = radians * DEGREE_FACTOR;
    10.     printf("%6.3f radians is %6.3f degree\n", radians, degree);
    11.     return 0;
    12. }
    In the future, please post comments outside the code tags. Only the code goes inside the code tags.
    Now, as for the explanation:
    1) "Includes" the stdio.h header. Basically the preprocessor takes the contents of the file and pastes it into the file where the #include is. stdio.h contains function prototypes for some functions, among them printf and scanf. A prototype allows the compiler to see if you are correctly calling a function.
    2) Creates a define named DEGREE_FACTOR whose value is 57.295779. Any instance of this define in the code is replaced with the actual number (or value) that it is defined to be by the preprocessor.
    3) Beginning of the definition of a function named main.
    4) Opening { for function.
    5 & 6) Defines variables of type double with names radians and degree.
    7) Outputs the text "Enter the angle in radians:" to the console screen.
    8) Takes the address of radians and passes it to scanf. %lf means scanf should read a double. Scanf reads a double and then stores it in the variable passed - in this case, radians.
    9) Multiplies radians by DEGREE_FACTOR (57.295779) and then assigns the result to the variable degree.
    10) Printf outputs information to the screen again. Printf parses the input text and outputs stuff accordingly. %f means output a float or double. It also specifies the precision (how many decimals) and how many leading 0s (I think), it should print. It also passes along the radians and degree variables to printf.
    11) Returns 0 from main. This will be returned to the OS.
    12) Closing } for the function.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by MK27 View Post
    Part of your translation does not make sense, but someone else may be able to intuit more.

    In the context of printf, lf would refer to datatype double. (On my system it's hard to see the point, since while one occupies twice as many bytes as the other, the precision on both of them craps out at the same point:
    Code:
    include <stdio.h>
    
    int main() {
    	float y=13000000.3453f;
    	double x=13000000.3453f;
    	printf("float is %d bytes\ndouble is %d bytes\n",sizeof(float),sizeof(double));
    	printf("y is %f, x is %lf\n",y,x);
    	return 0;
    }
    float is 4 bytes
    double is 8 bytes
    y is 13000000.000000, x is 13000000.000000
    )
    In the context of printf, "lf" doesn't mean a thing. "lf" means long double in the context of scanf. Since printf is variadic, all float arguments are promoted to double before printf even knows what's going on.

  7. #7
    Registered User
    Join Date
    Feb 2009
    Posts
    3
    Thanks for the responds.I'm really apprciate it.It's really help me to improve my explanation in my presentation.Thank you verymuch!!

    btw,sorry for the code tag.did'nt noticed that~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question for Prolog Experts
    By ssharish2005 in forum Tech Board
    Replies: 3
    Last Post: 02-03-2009, 02:59 AM
  2. New Contest (Possibly Too Easy for Experts)
    By Reisswolf in forum Contests Board
    Replies: 11
    Last Post: 01-29-2006, 10:40 AM
  3. check out this tutorial plz...even experts
    By KidMan in forum C Programming
    Replies: 1
    Last Post: 01-28-2006, 10:15 AM
  4. Major Help! Calling all experts.
    By hern in forum C Programming
    Replies: 3
    Last Post: 05-06-2004, 08:56 PM
  5. all experts in C programming
    By smoke_raffy2002 in forum C Programming
    Replies: 0
    Last Post: 10-13-2002, 12:49 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21