0% found this document useful (0 votes)
3 views5 pages

K242016

The document contains multiple C programming assignments with code snippets for different tasks. Assignment 2 includes code for calculating travel modes and costs based on money in a box, checking temperatures against a freezing point, and performing basic arithmetic operations. Each section provides user prompts and outputs results based on the input values.

Uploaded by

k242016
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)
3 views5 pages

K242016

The document contains multiple C programming assignments with code snippets for different tasks. Assignment 2 includes code for calculating travel modes and costs based on money in a box, checking temperatures against a freezing point, and performing basic arithmetic operations. Each section provides user prompts and outputs results based on the input values.

Uploaded by

k242016
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/ 5

K242016

M ZUNNORAIN

ASSIGNMENT 2

Q3

CODE:

#include <stdio.h>

int main() {
int moneyBox;
printf("Enter the amount in the money box: ");
scanf("%d", &moneyBox);

char* dayNames[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};

for (int i = 0; i < 5; i++) {


int dailyAmount = moneyBox;
moneyBox = 0;

printf("\n%s:\n", dayNames[i]);

char* travelMode;
int travelCost;

if (dailyAmount > 40) {


travelMode = "Rickshaw";
travelCost = 30;
} else if (dailyAmount >= 20 && dailyAmount <= 40) {
travelMode = "Bus";
travelCost = 16;
} else {
travelMode = "Bicycle";
travelCost = 0;
}

printf("Travel mode: %s\n", travelMode);


printf("Travel cost: %d rupees\n", travelCost);

int candyExpenses = (dailyAmount - travelCost) / 3 * 3;


printf("Candy expenses: %d rupees\n", candyExpenses);

int remainingAmount = dailyAmount - travelCost - candyExpenses;


printf("Remaining amount: %d rupees\n", remainingAmount);
moneyBox += remainingAmount;
}

printf("\nFinal amount in money box: %d rupees\n", moneyBox);

return 0;
}

OUTPUT: v

Q2

CODE: int main() {


float freezing_point;
printf("Enter the freezing point: ");
scanf("%f", &freezing_point);

for(int i = 1; i <= 5; i++) {


float temperature;
printf("Enter temperature %d: ", i);
scanf("%f", &temperature);

if(temperature < freezing_point) {


printf("Temperature %.2f is below the freezing point.\n", temperature);
} else if(temperature > freezing_point) {
printf("Temperature %.2f is above the freezing point.\n", temperature);
} else {
printf("Temperature %.2f is at the freezing point.\n", temperature);
}
}

return 0;
}

OUTPUT:

Q4

CODE:

#include <stdio.h>

int main() {
char operation;
printf("Enter operation (A/S/M/D): ");
scanf(" %c", &operation);
if (operation == 'A' || operation == 'a') {
int num1, num2;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
printf("%d + %d = %d\n", num1, num2, num1 + num2);
} else if (operation == 'S' || operation == 's') {
int num1, num2;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
if (num1 > num2) {
printf("%d - %d = %d\n", num1, num2, num1 - num2);
} else {
printf("%d - %d = %d\n", num2, num1, num2 - num1);
}
} else if (operation == 'M' || operation == 'm') {
int num1, num2;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
printf("%d * %d = %d\n", num1, num2, num1 * num2);
} else if (operation == 'D' || operation == 'd') {
int num1, num2;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
if (num2 != 0 && num1 != 0) {
if (num1 > num2) {
printf("%d / %d = %.2f\n", num1, num2, (float)num1 / num2);
} else {
printf("%d / %d = %.2f\n", num2, num1, (float)num2 / num1);
}
} else {
printf("Error: Division by zero.\n");
}
} else {
printf("Error: Invalid operation.\n");
}

return 0;
}

OUTPUT:
Q5

CODE:
OUTPUT:

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