{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

assignment 2

# assignment 2 - scanf"\n%f"&number sum = sum...

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

/* 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 */

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

View Full Document
#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:");

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

View Full Document
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

{[ snackBarMessage ]}