Presentation is loading. Please wait.

Presentation is loading. Please wait.

2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf.

Similar presentations


Presentation on theme: "2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf."— Presentation transcript:

1 2.3 Output Formatting

2 Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf (“%3d\n”, 25); The number of spaces, “c”, and number of decimals expressed %c.df,

3 Special Characters Other characters like % must be typed twice to be printed with printf as in printf(“ 50%\n”) \n prints a new line in printf statements Page 76-79 shows various formatting commands in a nice chart

4 Cast To force one type of expression into a certain data type – (Type)Expression

5 Increment and Decrement Operators A common programming operator is to increase a variable by 1. i++ or ++I i-- or --i

6 Evaluating Evaluating a math expression means assigning values to all variables and testing the result to determine if it is correct. 5 * (X + Y) - 4 * Y / (Z + 6) with X = 2, Y=3, and Z=6

7 Combo equal sign

8 Modulus Operator % symbol when it come to math operations divides the numbers and then return the remainder!!! 5%2 will return 1 as answer 7%5 will return 2 as answer 10%5will return 0 as answer 4%5 will return 4 as answer

9 Different Header Files #include time.h Stdlib.h

10 Rounding vs. Output Format

11 Random Number Generator Every Random number generator needs a “Seed”. Some key starting value. This line picks that seed value based off computer clock Sets the variable to a random number generated by rand() Stdlib.h includes the time() function and time.h is used to get system time

12 Exercises Write a program that reads a time interval in hours, minutes, and seconds, and converts this measurement to hours only. For example, if the inputs values were 13 hours and 15 minutes and 30 seconds, the output should be something like: 13 hours, 15 minutes, 30 seconds is 13.26 hours The general quadratic formula can be used to solve for the zeroes of a quadratic equation. Write a program which asks the user for values of A, B, and C from a quadratic equation, and then uses the general quadratic formula to solve for the zeroes. Warning: Depending upon the values for A, B, and C, you may get errors or crashes when you run your program. This is okay for this exercise! (a) Create a program generates a random value between 1 and N, where N is an integer specified by the user. (b) Modify your program to allow the user to specify the starting value and the ending value, both integers. (c) Modify your program to allow the user to specify the integer step between values. For example, numbers between -5 and 5 with a step of 2 could be (at random) -5, -3, -1, 1, 3, 5. (d) Modify your program so all values are real (decimal) values.


Download ppt "2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf."

Similar presentations


Ads by Google