notes2

Notes2

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: What we’ve learned so far • Basic structure of a C program • Printing output: printf • Reading in input: scanf • Basic arithmetic operations • Decision making: if statements • Debugging programs • Algorithms • Reading for this week • Chap. 3 • Section 4.10 Additional Options for printf / scanf • We used the following scanf and printf statements last week: – scanf( “%d”, &integer1 ); – printf( “Sum is %d\n\n”, sum ); – Here integer1 and sum were variables, and %d indicated the format of the data (we used %d for integer). • Other format types: – – – – – %d = decimal integer (can also be of the form %.3d, %5d or %5.3d) %f = floating point number (can also be of the form %.2f or %6.2f) %lf = double (use %f in printf statement, %lf in scanf statement) %c = character %s = string (in printf only) Example Program 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 /* More on printf */ #include <stdio.h> /* function main begins program execution */ int main() { float pie = 3.1416; printf( "\n%.3d is an integer.", 15 ); printf( "\n%.3f is a floating point number.", pie ); printf( "\n%s is a string\n", "aabbbcc" ); return 0; /* indicate that program ended successfully */ } /* end function main */ Example Program Output...
View Full Document

This note was uploaded on 03/02/2009 for the course ENGR 3 taught by Professor Ben-yaakov during the Fall '08 term at UCSB.

Ask a homework question - tutors are online