Chapter 3-p - Example 3.1 The program in Fig.3.1 shows the...

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

View Full Document Right Arrow Icon
Example 3.1 The program in Fig.3.1 shows the use of integer arithmetic to convert a given number of days into months and days. PROGRAM TO CONVERT DAYS TO MONTHS AND DAYS Program main () { int months, days ; printf("Enter days\n") ; scanf("%d", &days) ; months = days / 30 ; days = days % 30 ; printf("Months = %d Days = %d", months, days) ; } Output Enter days 265 Months = 8 Days = 25 Enter days 364 Months = 12 Days = 4 Enter days 45 Months = 1 Days = 15 _______________________________________________________________ Fig. 3.1 Illustration of integer arithmetic Example 3.2 Program of Fig.3.2 prints a sequence of squares of numbers. Note the use of the shorthand operator *= . The program attempts to print a sequence of squares of numbers starting from 2. The statement
Background image of page 1

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

View Full DocumentRight Arrow Icon
a *= a; which is identical to a = a*a; replaces the current value of a by its square. When the value of a becomes equal or greater than N (=100) the while is terminated. Note that the output contains only three values 2, 4 and 16. USE OF SHORTHAND OPERATORS
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/14/2010 for the course CS SS ZG653 taught by Professor Shanta during the Spring '09 term at Birla Institute of Technology & Science.

Page1 / 6

Chapter 3-p - Example 3.1 The program in Fig.3.1 shows the...

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

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