You are on page 1of 10

Scenerio 1

#include <stdio.h>

void sum() {

int num1, num2, result;

printf("Enter first number: ");

scanf("%d", &num1);

printf("Enter second number: ");

scanf("%d", &num2);

result = num1 + num2;

printf("Sum is: %d\n", result);

int main() {

sum(); // will call the function here

return 0;

Scenerio 2

#include <stdio.h>

void sum(int num1, int num2) {

int result;
result = num1 + num2;

printf("Sum is: %d\n", result);

int main() {

int a, b;

printf("Enter first number: ");

scanf("%d", &a);

printf("Enter second number: ");

scanf("%d", &b);

sum(a, b);

return 0;

Scenerio 3

#include <stdio.h>

int sum() {

int num1, num2, result;

printf("Enter first number: ");

scanf("%d", &num1);

printf("Enter second number: ");

scanf("%d", &num2);

result = num1 + num2;

return result;

}
int main() {

int result;

result = sum();

printf("Sum is: %d\n", result);

return 0;

Scenerio 4

#include <stdio.h>

void sum() {

int num1, num2, result;

printf("Enter first number: ");

scanf("%d", &num1);

printf("Enter second number: ");

scanf("%d", &num2);

result = num1 + num2;

printf("Sum is: %d\n", result);

int main() {

sum();

return 0;

}
Function Related Problems Lab

Problem 1 of Lab

#include<stdio.h>

float calcuPrt(float pizzaSize) {

float prt = pizzaSize * 0.15;

return prt;

int main () {

float pizzaSize = 11;

float prt_ate = calcuPrt(pizzaSize);

printf("Ahmad ate %f the pieces Pizza = \n ", prt_ate);

return 0;

}
Problem 2 of Lab

#include <stdio.h>

int calcTotalMarks(int phy, int pf, int calculas, int islamiat, int pakStudy) {

int totalMarks = phy + pf + calculas + islamiat + pakStudy;

return totalMarks;

float calcPercentage(int totalMarks) {

return (float)totalMarks / 500 * 100;

int main() {

int phy, pf, calculas, islamiat, pakStudy;

printf("Enter marks for 5 subjects (out of 100):\n");

printf("Enter marks for phy : ");

scanf("%d", &phy);

printf("Enter marks for PF : ");

scanf("%d", &pf);

printf("Enter marks for Calculas : ");

scanf("%d", &calculas);

printf("Enter marks for Islamiat : ");

scanf("%d", &islamiat);

printf("Enter marks for Pak Study: ");

scanf("%d", &pakStudy);
int totalMarks = calcTotalMarks(phy, pf, calculas, islamiat, pakStudy);

float percentage = calcPercentage(totalMarks);

printf("Total marks: %d \n", totalMarks);

printf("Percentage: %f \n", percentage);

return 0;

Problem of Days

dayNameDisplay(int dayNum) {

if (dayNum == 1) {

printf("Monday\n");

} else if (dayNum == 2) {

printf("Tuesday\n");

} else if (dayNum == 3) {

printf("Wednesday\n");

} else if (dayNum == 4) {

printf("Thursday\n");

} else if (dayNum == 5) {

printf("Friday\n");

} else if (dayNum == 6) {

printf("Saturday\n");

} else if (dayNum == 7) {

printf("Sunday\n");

} else {

printf("Invalid day number");


}

int main() {

int dayNum;

printf("Tell me the number of Day: ");

scanf("%d", &dayNum);

dayNameDisplay(dayNum);

return 0;

Problem of TriangleSides

#include <stdio.h>

int theValidTriangle(int a, int b, int c) {

if ((a + b > c) && (b + c > a) && (a + c > b)) {

return 1;

} else {

return 0;

}
}

int main() {

int a, b, c;

printf("Enter the three sides of the triangle: \n");

scanf("%d %d %d", &a, &b, &c);

if (theValidTriangle(a,b,c)) {

printf("The triangle with sides %d %d and %d is valid.\n", a, b, c);

} else {

printf("The triangle with sides %d %d and %d is not valid.\n", a, b, c);

return 0;

Problem of Vowels

Problem of Discount

#include <stdio.h>

int#include <stdio.h>

int main() {

float rice_price, sugar_price, oil_price, tea_price, milk_price;

float discounted_price;
float total_price = 0;

printf("Enter the price of rice: ");

scanf("%f", &rice_price);

total_price = total_price + rice_price;

printf("Enter the price of sugar: ");

scanf("%f", &sugar_price);

total_price = total_price + sugar_price;

printf("Enter the price of cooking oil: ");

scanf("%f", &oil_price);

total_price = total_price + oil_price;

printf("Enter the price of tea: ");

scanf("%f", &tea_price);

total_price = total_price + tea_price;

printf("Enter the price of milk: ");

scanf("%f", &milk_price);

total_price = total_price + milk_price;

if (total_price > 2000) {

discounted_price = total_price * 0.9;

printf("The customer get 10%% discount.\n");

printf("Total price after discount: %f\n", discounted_price);

} else {
printf("Total price: %f\n", total_price);

return 0;

You might also like