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

C Programs1

The document provides code examples for 3 C programs: 1) A program to find the maximum and minimum of 3 numbers entered by the user. 2) A program to calculate simple and compound interest given principal, rate, and time. 3) A program that takes a percentage as input and outputs the result ("FAIL", "SECOND", or "DISTINCTION") based on ranges for the percentage.

Uploaded by

vangalamohithsai
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)
16 views4 pages

C Programs1

The document provides code examples for 3 C programs: 1) A program to find the maximum and minimum of 3 numbers entered by the user. 2) A program to calculate simple and compound interest given principal, rate, and time. 3) A program that takes a percentage as input and outputs the result ("FAIL", "SECOND", or "DISTINCTION") based on ranges for the percentage.

Uploaded by

vangalamohithsai
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

1) program for finding the max and min from the three numbers

Code:
#include <stdio.h

int main() {

int num1, num2, num3;

printf("Enter three numbers: ");

scanf("%d %d %d", &num1, &num2, &num3);

int max = num1;

if (num2 > max) {

max = num2;

if (num3 > max) {

max = num3;

int min = num1;

if (num2 < min) {

min = num2;

if (num3 < min) {

min = num3;

printf("Maximum: %d\n", max);

printf("Minimum: %d\n", min);

return 0;

Output:
2) Write a program for simple, compound interest.

Code:

#include <stdio.h>

#include <math.h>

int main() {

float principal, rate, simpleInterest, compoundInterest;

int time;

printf("Enter principal amount: ");

scanf("%f", &principal);

printf("Enter rate of interest: ");

scanf("%f", &rate);

printf("Enter time (in years): ");

scanf("%d", &time);

simpleInterest = (principal * rate * time) / 100;

compoundInterest = principal * (pow((1 + rate / 100), time)) - principal;

printf("Simple Interest: %.2f\n", simpleInterest);

printf("Compound Interest: %.2f\n", compoundInterest);

return 0;

Output:
3) . WAP that declares <40% = FAIL, 40 to 60% = SECOND, 60 to 100% = DISTINCTION ,Read
percentage from standard input.

Code:

#include <stdio.h>

int main() {

float percentage;

printf("Enter the percentage: ");

scanf("%f", &percentage);

if (percentage < 40.0) {

printf("Result: FAIL\n");

} else if (percentage >= 40.0 && percentage <= 60.0) {

printf("Result: SECOND\n");

} else if (percentage > 60.0 && percentage <= 100.0) {

printf("Result: DISTINCTION\n");

} else {

printf("Invalid percentage entered. Please enter a percentage between 0 and 100.\n");

return 0;

Output:
4

You might also like