Learning the C language becomes much easier when you stop memorizing syntax and start solving real problems.
However, many beginners struggle when they try to apply simple concepts in real situations.
That’s where scenario-based questions help. Instead of directly telling you what to do, they push you to think, analyze, and build logic step by step.
In fact, recent learning trends (2025–2026) show that students improve problem-solving skills up to 60% faster when they practice real-world exercises instead of only reading theory.
In this article, you’ll solve practical scenarios, from shopping bills to space missions, using simple C programs. Each problem includes test cases, explanations, and working code to help you learn by doing.
Bookshop Bill Calculator

Imagine you are creating a program for a bookshop. Each book costs $10. You need to calculate the total cost for a customer based on the number of books they want to purchase. Write a C program to calculate the total bill.
Test Case
Input
Enter the number of books: 3
Expected Output
The total cost is: $30
Explanation
To calculate the total bill, first store the price of a single book, $10, in a variable. Then, prompt the user to enter the number of books they wish to purchase. After receiving the input, calculate the total cost by multiplying the number of books with the price of a single book
- First, the
book_costvariable is initialized to store the fixed price of a single book, which is $10. - The user is then prompted to enter the number of books they wish to purchase.
-
quantityvariable is used to store the number of books input by the user. - The program calculates the total cost by multiplying
book_costwith quantity, and the result is stored in thetotal_costvariable. - Finally, the program displays the calculated total cost to the user using the
printffunction.
#include <stdio.h>
int main() {
int book_cost = 10;
int quantity;
int total_cost;
printf("Enter the number of books: ");
scanf("%d", &quantity);
total_cost = book_cost * quantity;
printf("The total cost is: $%d\n", total_cost);
return 0;
}Eid Festival Gift Planner

During Eid, a family is preparing gift boxes for their relatives. In addition to the planned gifts, they also decide to prepare a few extra gift boxes.
Determine the total number of gifts prepared and the overall cost based on the price of each gift in C program.
Test Case
Input
Enter number of relatives: 12
Enter extra gifts: 3
Enter price of each gift: 15
Expected Output
Total gifts: 15
Total cost: $225
Explanation
- The program first asks the user to enter the number of relatives.
- Then, it asks for extra gifts planned.
- Both numbers are combined using
+to get the total gifts. - The program asks for the price of each gift from the user.
- To find the total cost, the total gifts are multiplied using
*with the price. This calculates the full amount spent. - Finally, the program prints the total number of gifts and the total cost clearly.
#include <stdio.h>
int main() {
int relatives, extra_gifts, total_gifts;
int gift_price, total_cost;
// Take user input
printf("Enter number of relatives: ");
scanf("%d", &relatives);
printf("Enter extra gifts: ");
scanf("%d", &extra_gifts);
printf("Enter price of each gift: ");
scanf("%d", &gift_price);
// Combine relatives and extra gifts
total_gifts = relatives + extra_gifts;
// Calculate total cost
total_cost = total_gifts * gift_price;
// Display results
printf("Total gifts: %d\n", total_gifts);
printf("Total cost: $%d\n", total_cost);
return 0;
}Road Trip Distance Calculator

You’re planning a road trip and want to calculate how far you’ll travel. You also have to consider the time spent on breaks. The car travels at a constant speed of 60 kilometers per hour. Write a C program to calculate the total distance traveled after subtracting the time spent on stops.
Test Case
Input
Enter the total travel time in hours: 5
Enter the total stop time in hours: 1
Expected Output
The total distance traveled is: 240.00 km
- The program starts by defining the car’s speed as 60 km/h.
- The user is prompted to input the total travel time in hours and the total time spent on stops in hours.
- The adjusted travel time is calculated by subtracting the stop time from the total travel time. The formula used in the program is
adjustedTime = totalTime - stopTime. - The distance traveled is then calculated using the formula
distance = speed * adjustedTime. - The program displays the total distance traveled, formatted to two decimal places using
printf.
#include <stdio.h>
int main() {
float speed = 60.0;
float totalTime, stopTime, adjustedTime, distance;
printf("Enter the total travel time in hours: ");
scanf("%f", &totalTime);
printf("Enter the total stop time in hours: ");
scanf("%f", &stopTime);
adjustedTime = totalTime - stopTime;
distance = speed * adjustedTime;
printf("The total distance traveled is: %.2f km\n", distance);
return 0;
}Salary Calculator

Imagine you work in a company on an hourly basis and are paid based on your hourly rate. Write a C program to calculate your weekly salary based on the hourly rate and the number of hours worked during the week. The salary should also include a fixed bonus.
Test Case
Input
Enter your hourly rate: 25
Enter the number of hours worked: 40
Expected Output
Your weekly salary is: $1050.00
- The program begins by asking the user to input their hourly rate and the number of hours worked during the week.
- The
hourlyRatevariable is used to store the hourly rate entered by the user. - The
hoursWorkedvariable is used to store the number of hours worked entered by the user. - The
base_salaryis calculated using the formulabase_salary=hourlyRate*hoursWorked. - A fixed bonus of $50 is added to the
base_salary, regardless of hours worked. The result is stored infinal_salaryvariable. - The program then displays the calculated weekly salary, formatted to two decimal places using
printf.
#include <stdio.h>
int main() {
float hourlyRate;
float hoursWorked;
float baseSalary, finalSalary;
printf("Enter your hourly rate: ");
scanf("%f", &hourlyRate);
printf("Enter the number of hours worked in a week: ");
scanf("%f", &hoursWorked);
baseSalary = hourlyRate * hoursWorked;
finalSalary = baseSalary + 50;
printf("Your weekly salary is: $%.2f\n", finalSalary);
return 0;
}School Bus Seat Planner

Imagine you are arranging a school trip, and need to assign students to buses. Each bus has 40 seats. Some students may have to share seats. Think about how to calculate the number of buses needed and how many seats will remain empty in the last bus. Write code for it in C langauge.
Test Case
Input
Enter total number of students: 95
Expected Output
Total buses needed: 3
Seats left in last bus: 25
Explanation
- First, the program asks the user for total students.
- Then, it also asks for bus capacity.
- Next, total buses are calculated using a formula that automatically adds one more bus if students are left.
- After that, the remaining students are found using
%. - Then, empty seats are calculated by subtracting students in the last bus from total capacity.
- Finally, the program displays total buses and empty seats.
#include <stdio.h>
int main() {
int students, bus_capacity;
printf("Enter total number of students: ");
scanf("%d", &students);
printf("Enter bus capacity: ");
scanf("%d", &bus_capacity);
// Calculate total buses without using if
int total_buses = (students + bus_capacity - 1) / bus_capacity;
// Students in last bus
int students_in_last_bus = students % bus_capacity;
// Empty seats in last bus
int empty_seats = bus_capacity - students_in_last_bus;
printf("Total buses needed: %d\n", total_buses);
printf("Empty seats in last bus: %d\n", empty_seats);
return 0;
}}Bank Balance Calculation

Imagine that you are managing a simple bank account, and you need to calculate the balance after a deposit and a withdrawal. Write a program in C language that takes the initial balance, the amount to deposit, and the amount to withdraw as inputs from the user, and then calculates and displays the final balance.
Test Case
Input
Enter the initial balance: 500
Enter the deposit amount: 200
Enter the withdrawal amount: 100
Output
Your final balance is: $600
- The program starts by asking the user to input the initial balance, the deposit amount, and the withdrawal amount.
- The
initialBalancevariable stores the amount of money the user currently has in their account. - The
depositAmountvariable stores the amount the user wants to deposit into their account. - The
withdrawalAmountvariable stores the amount the user wants to withdraw. - The final balance is calculated using the formula
finalBalance=initialBalance+depositAmount–withdrawalAmount, where the deposit amount is added to the initial balance, and the withdrawal amount is subtracted from it. - The program then displays the final balance to the user using printf.
#include <stdio.h>
int main() {
int initialBalance;
int depositAmount;
int withdrawalAmount;
int finalBalance;
printf("Enter the initial balance: ");
scanf("%d", &initialBalance);
printf("Enter the deposit amount: ");
scanf("%d", &depositAmount);
printf("Enter the withdrawal amount: ");
scanf("%d", &withdrawalAmount);
finalBalance = initialBalance + depositAmount - withdrawalAmount;
printf("Your final balance is: $%d\n", finalBalance);
return 0;
}Candy Party

Imagine you have a bag full of candies, and you want to share them equally among your friends so that everyone gets the same number of candies. After sharing, some candies might remain that cannot be distributed equally. Write a C program to calculate how many candies each friend will receive and how many candies will be left over.
Test Case
Input
Enter the total number of candies: 25
Enter the number of friends: 4
Expected Output
Each friend gets 6 candies.
Leftover candies: 1
- The program starts by asking the user to input the total number of candies and the number of friends they want to distribute them to.
- The
totalCandiesvariable stores the total number of candies the user has. - The
totalFriendsvariable stores the total number of friends who will receive candies. - The number of candies each friend will receive is calculated using integer division,
candiesPerFriend=totalCandies/totalFriends. This operation divides the total number of candies by the total number of friends and gives the result as the number of full candies each friend gets. - The leftover candies are calculated using the modulus operator,
leftoverCandies=totalCandies%totalFriends. This operation gives the remainder when dividing the total number of candies by the total number of friends, representing the leftover candies. - Finally, the program displays the number of candies each friend gets and the leftover candies.
#include <stdio.h>
int main() {
int candies;
int friends;
int candies_per_person;
int leftover_candies;
printf("Enter the total number of candies: ");
scanf("%d", &candies);
printf("Enter the number of friends: ");
scanf("%d", &friends);
candies_per_person = candies / friends;
leftover_candies = candies % friends;
printf("Each friend gets %d candies.\n", candies_per_person);
printf("Leftover candies: %d\n", leftover_candies);
return 0;
}Vacation Cost Calculation

Imagine you and your friends plan a vacation. The total cost of the vacation includes accommodation, food, and transportation expenses. The group decides to split the total cost equally among all members, but one person volunteers to pay an extra amount to cover tips and other small expenses. Write a C program to calculate how much each person has to pay and the total amount paid by the person covering the extra expenses.
Test Case
Input
Enter the cost of accommodation: 500
Enter the cost of food: 300
Enter the cost of transportation: 200
Enter the number of friends: 5
Enter the extra contribution amount: 50
Output
Each person owes: $200
The contributing person owes: $250
- The program begins by prompting the user to input the costs of accommodation, food, and transportation, which are stored in
accommodation,foodandtransportationrespectively. - Then the user is asked to input the number of friends and the extra contribution amount which is stored in
friendsandextraContributionvariables respectively. - The total cost of the vacation is calculated by adding the values of
accommodation,food, andtransportationand is stored intotalCostvariable. - The
totalCostis divided by thefriendsvariable to calculate the per-person share, and the result is stored inperPersonShare - The program then calculates the final amount for the person making the extra contribution by adding the
extraContributionto their share of the cost. The result is stored infinalAmount. - Finally, the program displays the per-person share for everyone else and the total amount paid by the contributing person using
printf.
#include <stdio.h>
int main() {
int accommodation;
int food;
int transportation;
int friends;
int extraContribution;
int totalCost;
int perPersonShare;
int finalAmount;
printf("Enter the cost of accommodation: ");
scanf("%d", &accommodation);
printf("Enter the cost of food: ");
scanf("%d", &food);
printf("Enter the cost of transportation: ");
scanf("%d", &transportation);
printf("Enter the number of friends: ");
scanf("%d", &friends);
printf("Enter the extra contribution amount: ");
scanf("%d", &extraContribution);
totalCost = accommodation + food + transportation;
perPersonShare = totalCost / friends;
finalAmount = perPersonShare + extraContribution;
printf("Each person owes: $%d\n", perPersonShare);
printf("The contributing person owes: $%d\n", finalAmount);
return 0;
}WW2 Supply Logistics

During World War II, supply trucks were used to deliver goods to soldiers. Each truck can carry only a limited amount of weight. Sometimes, the supplies do not fit perfectly into full trucks.
Instead of checking manually, think about how you can use the total supplies and truck capacity to figure out how many trucks are needed and how much weight will go in the last truck. Create logic for this in C.
Test Case
Input
Enter total supplies in kg: 4550
Expected Output
Total trucks needed: 5
Remaining supplies for last truck: 550 kg
Explanation
- The program first asks the user to enter total supplies and truck capacity.
- Total trucks are calculated so that even a small leftover gets its own truck.
- Then division (
/) is used to find how many full trucks are needed. - The remainder operator
%finds how much weight is left for the last truck. - Finally, the program prints the total trucks required and leftover supplies.
#include <stdio.h>
int main() {
int supplies, truck_capacity;
printf("Enter total supplies in kg: ");
scanf("%d", &supplies);
printf("Enter truck capacity: ");
scanf("%d", &truck_capacity);
// Calculate total trucks without using if
int total_trucks = (supplies + truck_capacity - 1) / truck_capacity;
// Remaining supplies in last truck
int leftover = supplies % truck_capacity;
printf("Total trucks needed: %d\n", total_trucks);
printf("Remaining supplies for last truck: %d kg\n", leftover);
return 0;
}Coffee Break Time

Imagine you are automating a coffee production system for a cafe. The machine produces 8 cups of coffee per hour. Write a program in C language to calculate how many full hours it will take to produce a certain number of cups, and how many cups will be left incomplete.
Test Case
Input
Enter the total cups needed: 25
Output
Full hours: 3
Remaining cups: 1
- The program takes the total number of cups needed as input and stores it in
total_cups. - The number of total cups is divided by 8 to find the
full_hourssince 8 cups can be made in one hour. - The modulus operator ‘
%‘ gives the remainder. The remaining cups are calculated using the modulus operator and stored inremaining_cups. - The
full_hoursandremaining_cupsare displayed to the user usingprintf.
#include <stdio.h>
int main() {
int total_cups;
printf("Enter the total cups needed: ");
scanf("%d", &total_cups);
int full_hours = total_cups / 8;
int remaining_cups = total_cups % 8;
printf("Full hours: %d\n", full_hours);
printf("Remaining cups: %d\n", remaining_cups);
return 0;
}Marathon Calories Burned

Imagine you’re developing a fitness tracking app for marathon runners. In this app, the goal is to calculate how many calories a runner burns based on the distance they run. A person burns 50 calories for every kilometer they run. Write a C program that takes the distance traveled in meters and calculates the calories burned by the marathon runner.
Test Case
Input
Enter the distance you ran (in meters): 7500
Output
You burned 375.00 calories by running 7.50 kilometers.
- In this program, first a constant variable
calories_per_kmis defined to store the value of calories burned per kilometer. - The program takes the distance traveled in meters as input using the
scanffunction and stores it in the variabledistance_meters. - The distance in meters is converted to kilometers by dividing
distance_metersby 1000, as 1 kilometer equals 1000 meters. The result is stored in the variabledistance_kilometers. - The total calories burned is calculated by multiplying
distance_kilometersbycalories_per_km. The result is stored in the variabletotal_calories. - The program displays the total calories burned and the distance in kilometers using the
printffunction.
#include <stdio.h>
int main() {
float distance_meters;
float distance_kilometers;
float total_calories;
const int calories_per_km = 50;
printf("Enter the distance you ran (in meters): ");
scanf("%f", &distance_meters);
distance_kilometers = distance_meters / 1000.0;
total_calories = distance_kilometers * calories_per_km;
printf("You burned %.2f calories by running %.2f kilometers.\n", total_calories, distance_kilometers);
return 0;
}Jungle Adventure Supplies

You and your friends are going on an exciting jungle adventure. Each person needs a food pack to stay energized. Each food pack can feed 4 people. Write a program to calculate how many food packs you need for your group and how many people will have to share from an additional pack.
Test Case
Input
Enter the total number of people: 13
Output
Food packs needed: 3
People without full packs: 1
- The program takes the total number of people in your group as input and stores it in the
total_peoplevariable. - The number of full food packs needed is calculated by dividing the total people by 4 using integer division and the result is stored in
packs_needed. - The number of people left without a full pack is calculated using the modulus operator and stored in
extra_people. - Finally, a two
printfstatements are used to display the results.
#include <stdio.h>
int main() {
int total_people;
printf("Enter the total number of people: ");
scanf("%d", &total_people);
int packs_needed = total_people / 4;
int extra_people = total_people % 4;
printf("Food packs needed: %d\n", packs_needed);
printf("People without full packs: %d\n", extra_people);
return 0;
}River Crossing Weight Calculation

You are transporting cargo across a river using boats. Each boat has a maximum weight limit of 200 kilograms, and each cargo box weighs exactly 50 kilograms. You need to calculate how many boats are required to transport all the cargo boxes safely. Write a program to calculate this based on the total number of cargo boxes provided by the user.
Test Case
Input
Enter the total number of cargo boxes: 9
Output
Total boats needed: 3
- The program takes the total number of cargo boxes as input and stores it in
total_boxes. - Each boat can carry 200 kg, which is equivalent to 4 cargo boxes.
- The number of boats needed is calculated by dividing the total number of cargo boxes by 4 and rounding up. This is done by adding 3 to the total number of boxes and then dividing by 4.
- The total boats needed are displayed using a
printf.
#include <stdio.h>
int main() {
int total_boxes;
printf("Enter the total number of cargo boxes: ");
scanf("%d", &total_boxes);
int boats_needed = (total_boxes + 3) / 4;
printf("Total boats needed: %d\n", boats_needed);
return 0;
}Desert Water Distribution

You are distributing water in a desert outpost. Each barrel holds exactly 60 liters of water, and each camel can carry 180 liters. Write a program to calculate how many camels are needed to transport a given number of barrels of water.
Test Case
Input
Enter the total number of barrels: 10
Output
Total camels needed: 4
- The program takes the total number of barrels as input and stores it in
total_barrels. - Each camel can carry 3 barrels (180/60 = 3).
- The total number of camels required is calculated by dividing the
total_barrelsby 3 and then rounding up. - For rounding up, 2 is added to
total_barrelsbefore dividing it by 3. This ensures there is an extra camel for any remainder.
#include <stdio.h>
int main() {
int total_barrels;
printf("Enter the total number of barrels: ");
scanf("%d", &total_barrels);
int camels_needed = (total_barrels + 2) / 3;
printf("Total camels needed: %d\n", camels_needed);
return 0;
}Treasure Game Scoring

You are designing a scoring system for a treasure hunt game. Each player collects gold coins during the game, and their final score is calculated based on the number of coins they collect. Each gold coin contributes 10 points to the player’s score. Additionally, players earn a bonus of 50 points for every full set of 25 coins they gather. Write a program in C language that calculates the total score for a player.
Test Case
Input
Enter the number of coins collected: 15
Output
Total score: 150
- The program takes the number of coins collected by the player as input and stores it in the
coins_collectedvariable. - Then the program calculates the
base_scoreby multiplying thecoins_collectedby 10. - The
bonus_pointsare calculated by first dividing the number of coins by 25. This will find out that how many complete sets of 25 coins are earned. Then these complete sets are multiplied by 50 to calculate the total bonus points. Players that have collected less than 25 coins will not get any bonus points. - The
total_scoreis calculated by adding thebase_scoreand thebonus_points. - Then the
total_scoreis displayed usingprintf.
#include <stdio.h>
int main() {
int coins_collected;
printf("Enter the number of coins collected: ");
scanf("%d", &coins_collected);
int base_score = coins_collected * 10;
int bonus_points = (coins_collected / 25) * 50;
int total_score = base_score + bonus_points;
printf("Total score: %d\n", total_score);
return 0;
}Space Mission Fuel Optimization

You are a scientist working on a space mission, and your job is to figure out how much fuel the spacecraft needs to reach a distant planet. The process has a few steps. First, you calculate the base fuel by multiplying the spacecraft’s weight (in tons) by the square of the distance to the planet (in million kilometers). Then, you adjust this base fuel by dividing it by the engine’s efficiency. To make sure the spacecraft is safe, you add a margin, which is found by multiplying the weight, distance, and efficiency together. Finally, you find the total fuel needed by subtracting the sum of the weight, distance, and efficiency from the adjusted fuel. Write a C program to do these calculations and find the total fuel required for the mission.
Test Case
Input
Enter the weight of the spacecraft (in tons): 10
Enter the distance to the planet (in million kilometers): 5
Enter the efficiency factor of the engine: 2
Expected Output
Total fuel required: 208
- First of all, the program takes the weight, distance and efficiency of the space craft from the user and stores it in
weight,distanceandefficiencyvariables respectively. - To find the
base_fuelthe program multiplies weight with the square of distance. The square of an integer variable can be calculated by multiplying it with itself. - Then the
base_fuelis divided byefficiencyfactor and the result is stored inadjusted_fuel. - The
safety_marginis calculated by multiplyingweight,distanceand theefficiencyfactor of the space craft. - The
total_fuelrequired is calculated by adding theadjusted_fuelandsafety_marginand then subtracting the sum ofweight,distanceandefficiencyfrom it.
#include <stdio.h>
int main() {
int weight;
int distance;
int efficiency;
printf("Enter the weight of the spacecraft (in tons): ");
scanf("%d", &weight);
printf("Enter the distance to the planet (in million kilometers): ");
scanf("%d", &distance);
printf("Enter the efficiency factor of the engine: ");
scanf("%d", &efficiency);
int base_fuel = weight * (distance * distance);
int adjusted_fuel = base_fuel / efficiency;
int safety_margin = weight * distance * efficiency;
int total_fuel = adjusted_fuel + safety_margin - (weight + distance + efficiency);
printf("Total fuel required: %d\n", total_fuel);
return 0;
}Bank Transaction Code Analyzer

Imagine that you are working for a banking system, and your job is to make it easier to analyze transaction codes. Each transaction code is a six-digit number, where every digit holds specific information about the transaction. To simplify the process, you need a way to break down these codes, understand their details, and perform basic calculations. Write a program in C that reads a six-digit transaction code from the user, separates it into individual digits, then calculates the sum and product of those digits, and finally displays the results.
Test Case
Input
Enter a six-digit transaction code: 123456
Expected Output
Digits: 1 2 3 4 5 6
Sum of digits: 21
Product of digits: 720
- First of all, the program takes the six-digit transaction code as input from the user and stores it in the
codevariable - To find the first digit, the program divides the
codeby 100000. This gives the digit in the hundred-thousands place. - To find the second digit, the program divides the
codeby 10000 and then calculates the remainder when divided by 10. This gives the digit in the ten-thousands place. - The third digit is found by dividing the
codeby 1000 and then taking the remainder when divided by 10. This gives the digit in the thousands place. - To find the fourth digit, the program divides the
codeby 100 and takes the remainder when divided by 10. This gives the digit in the hundreds place. - For the fifth digit, the program divides the
codeby 10 and takes the remainder when divided by 10. This gives the digit in the tens place. - Finally, the sixth digit is obtained by taking the remainder of the
codewhen divided by 10. This gives the digit in the units place. - The sum of all six digits is calculated by adding them together and the product of the digits is calculated by multiplying all six digits.
- Finally, the program displays each digit, the sum of the digits, and the product of the digits using
printf.
#include <stdio.h>
int main() {
int code;
printf("Enter a six-digit transaction code: ");
scanf("%d", &code);
int d1 = code / 100000;
int d2 = (code / 10000) % 10;
int d3 = (code / 1000) % 10;
int d4 = (code / 100) % 10;
int d5 = (code / 10) % 10;
int d6 = code % 10;
int sum = d1 + d2 + d3 + d4 + d5 + d6;
int product = d1 * d2 * d3 * d4 * d5 * d6;
printf("Digits: %d %d %d %d %d %d\n", d1, d2, d3, d4, d5, d6);
printf("Sum of digits: %d\n", sum);
printf("Product of digits: %d\n", product);
return 0;
}Math Puzzle Challenge

Imagine that you are designing a math-based game for students in which they will solve puzzles by entering a sequence of numbers. The game will evaluate the sequence to find two outcomes. The first outcome is the game score and the second outcome is the difficulty factor. This program should work on a sequence of 5 numbers. The weighted sum of the sequence is calculated by multiplying each number by its fixed position in the sequence and adding these values together. Additionally, the program calculates the product of all five numbers. The game score is then determined by adding the weighted sum and the product, and taking the remainder when divided by 100003 (a prime number). The difficulty factor is found by multiplying the total of all the numbers by their weighted sum, and then dividing the result by 99991 to get the remainder.
Write a program in C that calculates and displays the game score and difficulty factor based on the sequence of numbers entered.
Test Case
Input
Enter the first positive integer: 2
Enter the second positive integer: 4
Enter the third positive integer: 6
Enter the fourth positive integer: 8
Enter the fifth positive integer: 10
Expected Output
Game Score: 3950
Difficulty Factor: 3300
- The program starts by asking the user to input five positive integers at a time. Each number is stored in a separate variable.
- Then the
weighted_sumis calculated by multiplying each number by its position (1 to 5) and summing up these values. - The
productof the numbers is calculated by multiplying all five values together. - The
game_scoreis calculated by adding theweighted_sumand theproduct. After that we find it’s reminder when divided by100003. - The
difficulty_factoris determined by multiplying thetotal_sumof the numbers by theirweighted_sum, then taking the remainder when divided by 99991. - Finally, the program outputs both the
game_scoreand thedifficulty_factorusingprintf.
#include <stdio.h>
int main() {
int n1, n2, n3, n4, n5;
printf("Enter the first positive integer: ");
scanf("%d", &n1);
printf("Enter the second positive integer: ");
scanf("%d", &n2);
printf("Enter the third positive integer: ");
scanf("%d", &n3);
printf("Enter the fourth positive integer: ");
scanf("%d", &n4);
printf("Enter the fifth positive integer: ");
scanf("%d", &n5);
int weighted_sum = n1 * 1 + n2 * 2 + n3 * 3 + n4 * 4 + n5 * 5;
int total_sum = n1 + n2 + n3 + n4 + n5;
int product = n1 * n2 * n3 * n4 * n5;
int game_score = (weighted_sum + product) % 100003;
int difficulty_factor = (total_sum * weighted_sum) % 99991;
printf("Game Score: %d\n", game_score);
printf("Difficulty Factor: %d\n", difficulty_factor);
return 0;
}Online Exam Score Calculator

An online exam system evaluates students across 5 sections. Each section has a base mark, and fully completed sections earn bonus points. Additionally:
The platform applies a section multiplier for difficult sections.
Each section also includes a penalty deduction for minor mistakes.
Bonus points are added only if the section is fully completed.
Your task is to calculate the final total score by combining all these factors in C.
Test Case
Input
Enter marks for 5 sections: 20 18 25 22 15
Enter completion status (1=full, 0=partial) for each section: 1 1 1 0 1
Enter section multipliers: 2 1 3 2 1
Enter penalty points for each section: 2 0 5 1 2
Bonus points per full section: 10
Expected Output:
Total score: 194
Explanation
- First, the program asks the user to enter marks for all sections.
- Next, it collects the completion status (1 or 0) for each section.
- Then, it asks for a multiplier for each section. This increases the score for difficult sections.
- After that, it reads the penalty points for each section. This reduces the score for small mistakes.
- Each section’s intermediate score is calculated by:
- Multiplying base marks with section multiplier.
- Subtracting penalties.
- Adding bonus points only if the section is fully completed.
- Finally, all section scores are added together to get the final total score.
- The result is displayed on the screen.
#include <stdio.h>
int main() {
int m1, m2, m3, m4, m5; // Marks for 5 sections
int c1, c2, c3, c4, c5; // Completion status (1=full, 0=partial)
int mult1, mult2, mult3, mult4, mult5; // Section multipliers
int p1, p2, p3, p4, p5; // Penalty points
int bonus; // Bonus per full section
// Step 1: Take marks as input
printf("Enter marks for 5 sections: ");
scanf("%d %d %d %d %d", &m1, &m2, &m3, &m4, &m5);
// Step 2: Take completion status
printf("Enter completion status (1=full, 0=partial) for each section: ");
scanf("%d %d %d %d %d", &c1, &c2, &c3, &c4, &c5);
// Step 3: Take section multipliers
printf("Enter section multipliers: ");
scanf("%d %d %d %d %d", &mult1, &mult2, &mult3, &mult4, &mult5);
// Step 4: Take penalties
printf("Enter penalty points for each section: ");
scanf("%d %d %d %d %d", &p1, &p2, &p3, &p4, &p5);
// Step 5: Take bonus points
printf("Bonus points per full section: ");
scanf("%d", &bonus);
// Calculate final total score
int total = (m1 * mult1 - p1 + bonus * c1) +
(m2 * mult2 - p2 + bonus * c2) +
(m3 * mult3 - p3 + bonus * c3) +
(m4 * mult4 - p4 + bonus * c4) +
(m5 * mult5 - p5 + bonus * c5);
printf("Total score: %d\n", total);
return 0;
}Black Friday Shopping Total

During a Black Friday sale, a shopper buys 4 items. Each item has:
A base price.
A discount (applied only if eligible).
A tax (percentage of the discounted price).
A shipping fee (fixed per item).
Your task is to calculate the final total cost of all items using only operators, step by step.
Think about how to adjust each item price first (discount → tax → shipping), then sum them for the final total.
Test Case
Input
Enter price of item 1: 50
Discount eligible? (1=yes, 0=no): 1
Enter price of item 2: 30
Discount eligible? (1=yes, 0=no): 0
Enter price of item 3: 70
Discount eligible? (1=yes, 0=no): 1
Enter price of item 4: 40
Discount eligible? (1=yes, 0=no): 0
Fixed discount amount: 10
Tax percentage per item: 5
Shipping fee per item: 2
Expected Output
Final total cost: $222
Explanation
- First, the program asks the user to enter the base price of each item.
- Next, it collects whether a discount applies (1=yes, 0=no) for each item.
- Then, it asks for discount amount, tax percentage, and shipping fee.
- For each item:
- Apply discount by subtracting it only if eligible.
- Calculate tax on the discounted price.
- Add the shipping fee.
- Each item’s final price is calculated by subtracting the discount (if eligible), adding tax on the discounted price, and then adding the shipping fee, all using
-,*, and+operators. - Finally, all item prices are added together to get the total cost.
- The result is displayed on the screen.
#include <stdio.h>
int main() {
int p1, p2, p3, p4; // Base prices
int d1, d2, d3, d4; // Discount eligibility (1=yes, 0=no)
int discount, tax_percent, shipping;
printf("Enter price of item 1: ");
scanf("%d", &p1);
printf("Discount eligible? (1=yes, 0=no): ");
scanf("%d", &d1);
printf("Enter price of item 2: ");
scanf("%d", &p2);
printf("Discount eligible? (1=yes, 0=no): ");
scanf("%d", &d2);
printf("Enter price of item 3: ");
scanf("%d", &p3);
printf("Discount eligible? (1=yes, 0=no): ");
scanf("%d", &d3);
printf("Enter price of item 4: ");
scanf("%d", &p4);
printf("Discount eligible? (1=yes, 0=no): ");
scanf("%d", &d4);
printf("Fixed discount amount: ");
scanf("%d", &discount);
printf("Tax percentage per item: ");
scanf("%d", &tax_percent);
printf("Shipping fee per item: ");
scanf("%d", &shipping);
// Adjust each item price: discount -> tax -> shipping
int item1 = (p1 - discount * d1) + ((p1 - discount * d1) * tax_percent) / 100 + shipping;
int item2 = (p2 - discount * d2) + ((p2 - discount * d2) * tax_percent) / 100 + shipping;
int item3 = (p3 - discount * d3) + ((p3 - discount * d3) * tax_percent) / 100 + shipping;
int item4 = (p4 - discount * d4) + ((p4 - discount * d4) * tax_percent) / 100 + shipping;
// Calculate final total cost
int total = item1 + item2 + item3 + item4;
printf("Final total cost: $%d\n", total);
return 0;
}Try These Scenarios Yourself
Want to test these programs instantly?
Try them now using our C Online Compiler and see real-time results without installing anything.
