define replaces all occurrences of the text you specify with value you specify

Define replaces all occurrences of the text you

This preview shows page 11 - 16 out of 18 pages.

#define replaces all occurrences of the text you specify with value you specify Example: #define KMS_PER_MILES 1.60 #define PI 3.14159
Image of page 11
12 Comments /* Converts distances from miles to kilometers */ #include <stdio.h> /* printf, scanf definitions */ #define KMS_PER_MILE 1.609 /* conversion constant */ int main(void) { double miles, //distance in miles kms; //equivalent distance in kilometers //Get the distance in miles printf("Enter the distance in miles> "); scanf("%lf", &miles); //Convert the distance to kilometers kms = KMS_PER_MILE * miles; //Display the distance in kilometers printf("That equals %f kilometers.\n", kms); return (0); }
Image of page 12
13 Comments Comments provide supplementary information making it easier for us to understand the program, but are ignored by the C compiler. Two forms of comments: /* */ - anything between them with be considered a comment, even if they span multiple lines. // - anything after this and before the end of the line is considered a comment. Comments are used to create Program Documentation Information that help others read and understand the program. The start of the program should consist of a comment that includes programmer’s name, date of the current version, and a brief description of what the program does. Always Comment your Code!
Image of page 13
14 The “main” Function /* Converts distances from miles to kilometers */ #include <stdio.h> /* printf, scanf definitions */ #define KMS_PER_MILE 1.609 /* conversion constant */ int main(void) { double miles, //distance in miles kms; //equivalent distance in kilometers //Get the distance in miles printf("Enter the distance in miles> "); scanf("%lf", &miles); //Convert the distance to kilometers kms = KMS_PER_MILE * miles; //Display the distance in kilometers printf("That equals %f kilometers.\n", kms); return (0); }
Image of page 14
15 The “main” Function The heading int main(void) marks the beginning of the main function where program execution begins. Every C program has a main function. Braces ({,}) mark the beginning and end of the body of function main.
Image of page 15
Image of page 16

You've reached the end of your free preview.

Want to read all 18 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes