Assignment 2 - scanf"\n%f"&number sum = sum number printf"Enter a third number" scanf"\n%f"&number sum = sum

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

View Full Document Right Arrow Icon
/* Assignment 2, Part A, Question 2.1 */ #include <stdio.h> /* Finds the average of 3 numbers entered by user */ int main() { float num1, num2, num3, total, ave; printf("Enter a number:"); scanf("\n%f", &num1); printf("Enter a second number:"); scanf("\n%f", &num2); printf("Enter a third number:"); scanf("\n%f", &num3); total = num1 + num2 + num3; ave = total/3.0; printf("The average of %5.2f and %5.2f and %5.2f is %5.2f\n", num1, num2, num3, ave); return(0); } /* Assignment 2, Part A, Question2.2 */
Background image of page 1

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

View Full DocumentRight Arrow Icon
#include <stdio.h> /* Finds the average of 3 numbers entered by user */ int main() { float number, sum, ave; sum = 0; printf("Enter a number:"); scanf("\n%f", &number); sum = sum + number; printf("Enter a second number:");
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 DocumentRight 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: scanf("\n%f", &number); sum = sum + number; printf("Enter a third number:"); scanf("\n%f", &number); sum = sum + number; ave = sum/3.0; printf("The average of the three numbers is: %5.2f\n", ave); return(0); } /* Assignment 2, Part B, Question 2 */ #include <stdio.h> /* Determine whether entered year is a leap yr or not */ int main() { int year, year4, year100, year400; printf("\nEnter a year:"); scanf("\n%d", &year); year4 = year % 4; year100 = year % 100; year400 = year % 400; if (0 == year4 && 0 != year100 | | 0 == year400) printf("\nThe year %d is a leap year\n", year); else printf("The year %d is not a leap year\n", year); return(0); }...
View Full Document

This document was uploaded on 01/22/2011.

Page1 / 4

Assignment 2 - scanf"\n%f"&number sum = sum number printf"Enter a third number" scanf"\n%f"&number sum = sum

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