0% found this document useful (0 votes)
28 views4 pages

Shane Cunningham Classwork Com Sci

The document contains a C program with various functions to perform tasks such as checking if a number is prime, determining leap years, calculating simple interest, and finding areas of geometric shapes. It includes a main function that allows users to choose which operation to execute based on their input. The program is structured with multiple functions to handle different calculations and outputs results accordingly.

Uploaded by

shamarasharpe48
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views4 pages

Shane Cunningham Classwork Com Sci

The document contains a C program with various functions to perform tasks such as checking if a number is prime, determining leap years, calculating simple interest, and finding areas of geometric shapes. It includes a main function that allows users to choose which operation to execute based on their input. The program is structured with multiple functions to handle different calculations and outputs results accordingly.

Uploaded by

shamarasharpe48
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Shane Cunningham

Computer Science Classwork


Feb 21 2025

#include <stdio.h>
#include <math.h>

// 1. Check if a number is prime void


checkPrime(int num) { if (num < 2)
{ printf("%d is not a prime number.\n",
num); return;
}
for (int i = 2; i <= sqrt(num); i++) { if (num
% i == 0) { printf("%d is not a prime
number.\n", num); return;
}
}
printf("%d is a prime number.\n", num);
}

// 2. Check if a year is a leap year void checkLeapYear(int


year) { if ((year % 4 == 0 && year % 100 != 0) || (year %
400 == 0)) printf("%d is a leap year.\n", year); else
printf("%d is not a leap year.\n", year);
}

// 3. Check if a number is even or odd


void checkEvenOdd(int num) { if
(num % 2 == 0) printf("%d is
even.\n", num); else
printf("%d is odd.\n", num);
}

// 4. Find the greatest of three numbers void


findGreatest(int a, int b, int c) { int max = (a > b) ?
((a > c) ? a : c) : ((b > c) ? b : c); printf("The
greatest number is %d.\n", max);
}

// 5. Calculate simple interest void


simpleInterest(float p, float r, float t)
{ float si = (p * r * t) / 100;
printf("Simple Interest: %.2f\n", si);
}
// 6. Multiplication table up to 10 void
multiplicationTable(int num) { for (int i = 1; i
<= 10; i++) { printf("%d x %d = %d\n",
num, i, num * i);
}
}

// 7. Convert Celsius to Fahrenheit void


celsiusToFahrenheit(float celsius) { float fahrenheit = (celsius
* 9 / 5) + 32; printf("%.2f Celsius = %.2f Fahrenheit\n",
celsius, fahrenheit);
}

// 8. Sum of digits void


sumOfDigits(int num)
{ int sum = 0; while
(num > 0) { sum +=
num % 10; num /= 10;
}
printf("Sum of digits: %d\n", sum);
}

// 9. Input and print employee details void


employeeDetails() {
int id;
char name[50];
float salary;

printf("Enter Employee ID: ");


scanf("%d", &id); printf("Enter
Name: "); scanf("%s", name);
printf("Enter Salary: ");
scanf("%f", &salary);

printf("\nEmployee Details:\nID: %d\nName: %s\nSalary: %.2f\n", id, name, salary);


}

// 10. Calculate area of circle, square, triangle, and rectangle


void calculateAreas() { float radius, side, length, breadth,
base, height;
// Circle printf("Enter radius of circle: ");
scanf("%f", &radius); printf("Area of Circle: %.2f\n",
M_PI * radius * radius);

// Square printf("Enter side of square: ");


scanf("%f", &side); printf("Area of Square:
%.2f\n", side * side);

// Rectangle printf("Enter length and breadth


of rectangle: "); scanf("%f %f", &length,
&breadth);
printf("Area of Rectangle: %.2f\n", length * breadth);

// Triangle printf("Enter base and height of


triangle: "); scanf("%f %f", &base, &height);
printf("Area of Triangle: %.2f\n", 0.5 * base * height);
}

int main() { int choice, num,


a, b, c, year; float p, r, t,
celsius;

printf("Choose a program to execute (1-10): ");


scanf("%d", &choice);

switch (choice) {
case 1:
printf("Enter a number: ");
scanf("%d", &num);
checkPrime(num); break;
case 2:
printf("Enter a year: ");
scanf("%d", &year);
checkLeapYear(year);
break;
case 3:
printf("Enter a number: ");
scanf("%d", &num);
checkEvenOdd(num);
break; case 4:
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
findGreatest(a, b, c); break;
case 5:
printf("Enter Principal, Rate and Time: ");
scanf("%f %f %f", &p, &r, &t);
simpleInterest(p, r, t); break; case
6:
printf("Enter a number: ");
scanf("%d", &num);
multiplicationTable(num);
break; case 7:
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
celsiusToFahrenheit(celsius); break;
case 8:
printf("Enter a number: ");
scanf("%d", &num);
sumOfDigits(num);
break; case 9:
employeeDetails();
break; case 10:
calculateAreas(); break;
default:
printf("Invalid choice!\n");
}
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy