Name: Muhammad Waseef
Registration Number: FA23-BSE-083
Section: 2R
Dated: 17th October 2024
Submitted to: Jawad Khan
Lab Task: Programming Fundamentals
Task 1:
#include <stdio.h>
int main(){
printf("Muhammad Waseef\nFA23-BSE-083\n\n");
int num;
printf("Enter the Number:");
scanf("%d",&num);
if (num %2 == 1){
printf("The Number is Odd.\n");
}
else{
printf("The Number is Even.");
}
}
Task 2:
#include <stdio.h>
int main() {
printf("Muhammad Waseef\nFA23-BSE-083\n\n");
int year;
printf("Enter a year: ");
scanf("%d", &year);
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
printf("The year %d is a leap year.\n", year);
} else {
printf("The year %d is not a leap year.\n", year);
}
Task 3:
#include <stdio.h>
int main() {
printf("Muhammad Waseef\nFA23-BSE-083\n\n");
int zainAge,shanAge, aliAge;
printf("Enter Zain's Age:");
scanf("%d",&zainAge);
printf("Enter Shan's Age:");
scanf("%d",&shanAge);
printf("Enter Ali's Age:");
scanf("%d",&aliAge);
if(zainAge<shanAge && zainAge<aliAge){
printf("Zain is the Youngest.\n");
} else if (shanAge<aliAge && shanAge<zainAge) {
printf("Shan is the youngest.\n");
} else if (aliAge<zainAge && aliAge<shanAge) {
printf("ALi is the youngest.\n");
} else {
printf("Same Age is Found. Can't Proceed.\n");
}
Task 4:
#include <stdio.h>
int main() {
printf("Muhammad Waseef\nFA23-BSE-083\n\n");
float costPrice=0, sellPrice=0;
float profit, loss;
printf("Enter the cost price: ");
scanf("%f", &costPrice);
printf("Enter the selling price: ");
scanf("%f", &sellPrice);
if (sellPrice > costPrice) {
profit = sellPrice - costPrice;
printf("The seller has a profit of %.2f.\n", profit);
} else if (sellPrice < costPrice) {
loss = costPrice - sellPrice;
printf("The seller has a loss of %.2f.\n", loss);
} else {
printf("Prices are same, No loss or profit.\n");
}
return 0;
}
Task 5:
#include <stdio.h>
int main() {
printf("Muhammad Waseef\nFA23-BSE-083\n\n");
float length, breadth, area, perimeter;
printf("Enter the length of the rectangle: ");
scanf("%f", &length);
printf("Enter the breadth of the rectangle: ");
scanf("%f", &breadth);
area = length * breadth;
perimeter = 2 * (length + breadth);
if (area > perimeter) {
printf("The area is %.2fm of rectangle is greater than perimeter %.2fm.\n", area,
perimeter);
} else if (area < perimeter) {
printf("The area %.2fm of rectangle is less than perimeter %.2fm.\n", area, perimeter);
} else {
printf("The area %.2fm of rectangle is equal to perimeter %.2fm.\n", area, perimeter);
}
return 0;
}
Task 6:
#include <stdio.h>
int main() {
printf("Muhammad Waseef\nFA23-BSE-083\n\n");
int age;
char health;
char gender;
char location;
int premium = 0;
int amount = 0;
printf("Enter health status ('e' for excellent, 'p' for poor): ");
scanf(" %c", &health);
printf("Enter gender ('m' for male, 'f' for female): ");
scanf(" %c", &gender);
printf("Enter location ('c' for city, 'v' for village): ");
scanf(" %c", &location);
printf("Enter age: ");
scanf("%d", &age);
if (health == 'e' && age >= 25 && age <= 35 && location == 'c') {
if (gender == 'm') {
premium = 4;
amount = 200000;
} else if (gender == 'f') {
premium = 3;
amount = 100000;
}
} else if (health == 'p' && age >= 25 && age <= 35 && location == 'v' && gender == 'm') {
premium = 6;
amount = 10000;
}
if (premium > 0) {
printf("The person should be insured.\n");
printf("Premium: Rs. %.d per thousand\n", premium);
printf("Amount for insurance: Rs. %d\n", amount);
} else {
printf("The person has no insurance.\n");
}
return 0;
}
Task 7:
#include <stdio.h>
int main() {
printf("Muhammad Waseef\nFA23-BSE-083\n\n");
float A_marks, B_marks;
float percent_A, percent_B;
printf("Enter marks obtained in subject A: ");
scanf("%f", &A_marks);
printf("Enter marks obtained in subject B: ");
scanf("%f", &B_marks);
percent_A = A_marks;
percent_B = B_marks;
if (percent_A >= 55 && percent_B >= 45) {
printf("The student has passed.\n");
} else if (percent_A < 55 && percent_A >= 45 && percent_B >= 55){
printf("The student has passed.\n");
} else if (percent_B >= 65 && percent_A < 45) {
printf("The student has to reappear for subject A.\n");
} else if (percent_A >= 65 && percent_B < 45) {
printf("The student has to reappear for subject B.\n");
} else {
printf("The student has failed.\n");
}
Task 8:
#include <stdio.h>
int main() {
printf("Muhammad Waseef\nFA23-BSE-083\n\n");
float time;
printf("Enter the time taken: ");
scanf("%f", &time);
if (time >= 2 && time < 3) {
printf("The worker is highly efficient.\n");
} else if (time >= 3 && time < 4) {
printf("The worker should improve speed.\n");
} else if (time >= 4 && time < 5) {
printf("The worker should be trained to speed up.\n");
} else if (time >= 5) {
printf("The worker has to leave.\n");
} else {
printf("Invalid input.\n");
}