02_FundamentalsA(Sep.14)

02_FundamentalsA(Sep.14) - 6h 62,FunolaMemb A Screencasts...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

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

View Full Document Right Arrow Icon
Background image of page 2
Background image of page 3

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

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

Unformatted text preview: 6h 62; ,FunolaMemb A ( Screencasts I -— IV) (D inmate openrng dowmnfafion Tn w -Porm o—P a commem‘ sta'temen't (=9 TnoLen-ted ~— mabing 7+ ew‘er To VeAd ® befi'er V&W&b‘e harm: ‘Hua‘t‘ aeson‘be w dark +0 be shred @ blamk— li‘ms are used *0 semee blades 04* code @ pmrupi's are pwm‘owd To +k! user so «My +ku/ Knob) WM *0 ewber. a) TM (Mada-tic}? F5 wwmg \- \ area 2 = area \ \ s s ‘9 area? =2vea‘ ~99 404589425 4o46.&’Se¢2; ‘0) Wafch ow’r {or n‘ndwfyu‘on M50 (60 ‘ Endamenbls A 86;». I4 ~ 20(0 #3 / '16 ~X- AWN = i- Pate : 4? Purpose = Prompts The user ‘99: +14 pn‘ce up an arude beCore -ra>< *' and PVTW'B ‘Hw cost aF-Hu art-Jae I‘ncluph‘ng GST and PST +/ at Tnduol€ < stdn‘o . k) =3 Tnc\ude C 8'1’0‘ ML )1) 3:01AM PST 0.0; ‘fide'kne GIST 0.05 7'“ "‘3" f von) f daubu prim Be-Gorfl‘ax; doubu PWWWTaxJ PWM‘?‘ "Please enw pn‘ce be-Gore 13x = ")5 SCAM"l l “ (791‘? ", ¢pVTaB€PoreTu)j PYTCEA‘FWTM =vaceBcPof€Téx -x— ( LO+ PST *"stTH vaarx‘H> ("3’ch 39W ‘hw : 3, z“ rz-(r‘\n')' PficpA'HZZITW)j Wm { " mas; " ); return 0) 3 APSC Ibo Fundszs A 3gp. J4—2olo (993C I (so Fundamentals A 56?. l4— 2010 4. In this exercise we will investigate the use of format specifiers to control the way that output appears on the screen. When printing values of type double, format specifiers have the following form, in general: "%X.Yf" with a + or ~ sign optionally appearing before the X. Y represents a positive integer that controls the number of decimal places that are displayed. if Y is not specified, the default number of decimal places is 6. 50, "%f" indicates that the number is to be printed to 6 decimal places. X represents a positive integer that controls the width of the field in which the number is to be displayed. If X is not specified, the number is displayed in a field just wide enough to print the number to the specified (or default) number of decimal places. So, "%8f" indicates that the number is to be printed in a field of width 8 characters. Note that the number is aligned on the right hand side of the field, by default. if there‘s a "—" sign in front of the X, the number is aligned on the left hand side ofthe field in which it is printed. If there's a "+" sign in front of the X, the sign of the number is always printed. 50, if the number is positive, a + sign will be printed immediately preceding the number. Suppose the following variable declarations have been made: double a = 4.5236643231; double b = -6.43864l76; Determine the output from each of the following printf statements. The first two are done for you —— make sure you understand them before you move on. I rintf statement printf( "%f\n", a ); printf( "%f\n", b ); printf( "%.3f\n", a ); printf( "%.5f\n", b ); printf( "%6.2f\n", a ); printf( "%7.l " b ); printf( "%—6. 64.lf\n", a, b ); printf( "%—7- 6+5-lf\n", b, a )r' l—h / :3 I H) o l H] o 5. Write a program that prompts the user for the length, width and height of a solid steel rectangular bar (in metres). The program must then compute the mass of the bar in kilograms assuming that the density of the steel is 7850 kg per cubic metre. Recall that: mass = density x volume. PrPsc [60 Rimmeb A Sea s4 .— 20m #5 /* * Author: Paul Carter * Date: Sep 14, 2010 * Purpose: prompts user for length, width & height of steel * rectangular bar (in metres) and computes mass of bar in * kilograms assuming density of STEELwDENSITY kg/cu.m. */ #include <stdio.h> #include <stdlib.h> #define ST LL DENSITY 7850.0 L; int main( void ) { double length; double width; double height; double mass; printf( "Enter length of bar (metres): " ); scanf( "%lf", &length ); printf< "Enter width of bar (metres): " ); scanf( "%lf", &Width ); printf( "Enter height of bar (metres): " ); scanf( "%lf", &height ); XJ 1.) 7‘ U ll mass ( length * width * height ) * STU} ?NSTTY; printf( "Mass of bar = %f kg\n", mass ); system< "PAUSE" ); return 0; ...
View Full Document

{[ snackBarMessage ]}

Page1 / 4

02_FundamentalsA(Sep.14) - 6h 62,FunolaMemb A Screencasts...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online