{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

C__DOCUME~1_MAXWID~1_LOCALS~1_Temp_plugtmp-27_TTh_lecture03_formattedIO

C__DOCUME~1_MAXWID~1_LOCALS~1_Temp_plugtmp-27_TTh_lecture03_formattedIO

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1 TTh Lecture 3 1 EE312 - Lecture 3 Announcements Read chapters 5 and 6 for next class Topics for today will address: – Review – Formatted input and output – Introduction to Control Statements TTh Lecture 3 2 Short Term Schedule
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 TTh Lecture 3 3 Compute the Volume /* this program computes and outputs the volume of a box */ #include <stdio.h> int main(void) { int height, length, width, volume; height = 5; length = 20; width = 10; volume = height * length * width; printf ("The height is %d\n", height); printf ("The length is %d\n", length); printf ("The width is %d\n", width); printf ("The volume is %d\n", volume); return 0; } TTh Lecture 3 4 Converting Fahrenheit to Celsius /* program to convert a given Fahrenheit temperature to Celsius */ #include <stdio.h> #define FREEZING_PT 32.0 #define SCALE_FACTOR (5.0 / 9.0) int main(void) { float Fahrenheit, Celsius; printf ("Enter Fahrenheit temperature: "); scanf ("%f", &Fahrenheit); Celsius = SCALE_FACTOR * (Fahrenheit - FREEZING_PT); printf ("\nCelsius equivalent is: %.1f\n", Celsius); return 0; } /* program to convert a given Fahrenheit temperature to Celsius */ #include <stdio.h> int main(void) { const float FREEZING_PT = 32.0; const float SCALE_FACTOR = 5.0 / 9.0; float Fahrenheit, Celsius; printf ("Enter Fahrenheit temperature: "); scanf ("%f", &Fahrenheit); Celsius = SCALE_FACTOR * (Fahrenheit - FREEZING_PT); printf ("\nCelsius equivalent is: %.1f\n", Celsius); return 0; }
Image of page 2
3 Formatted Input and Output For simplifying the process of inputting values into and out of your program while its running. • The stdio library contains a function for reading values from the keyboard (the standard input device) and a function for writing out values to the screen (the standard output device) according to a given format specification. The functions are named: – scanf ( ), and printf ( ) You may use these from now on in your assignments. Input device values Your program running on the computer values Output device TTh Lecture 3 6 printf() function (1) printf ( "Format string in quotes", list-of- values) Defined in a library. Declared in <stdio.h> printf ("Double %d is %d \n", x, 2 * x ); Conversion specifications Values to be printed Format string Escape character
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 TTh Lecture 3 7 Escape Sequences (1) String literals sometimes need to contain control characters (such as tab and newline) or characters that have a special meaning in C (such as "). These characters are represented by escape sequences. Character escapes consist of \ followed by one character: alert (bell) \a backslash \\ backspace \b question mark \? form feed \f single quote \' new-line \n double quote \" carriage return \r horizontal tab \t vertical tab \v TTh Lecture 3 8 Escape Sequences (2) Writing the \a escape causes a beep. Writing the \n escape causes the cursor to move to the beginning of the next line. Writing the \t escape causes the cursor to move to the next tab stop.
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern