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

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

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

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

View Full Document
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
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
Ask a homework question - tutors are online