ISTANBUL AYDIN UNIVERSITY
FACULTY OF ENGINEERING
SEN118 COMPUTER PROGRAMMING
FINAL ASSIGNMENT
Group Members:
1. Miraç ŞABANOĞLU (B2505.160002)
Department of Engineering
2. Remziye Tuğba KAZANCI (B2505.160050)
Department of Engineering
3. Zaid MOUKAYEZ (B2505.150015)
Department of Civil Engineering
Teacher Name-Surname:
Assist. Prof. Dr. Mohammed ALKRUNZ
May 2026
Question 1
Code:
#include <stdio.h>
int main() {
float length, width;
printf("Enter the length:\n");
scanf("%f", &length);
printf("Enter the width:\n");
scanf("%f", &width);
printf("\nPerimeter = %f\n", 2 * (length + width));
printf("Area = %f\n", length * width);
return 0;
}
Print-screen of the output:
Question 2
Code:
#include <stdio.h>
int main()
{
float baseFare, costPerKm, kilometers, waitingCharge, totalFare;
printf("Enter base fare:\n");
scanf("%f", &baseFare);
printf("Enter cost per kilometer:\n");
scanf("%f", &costPerKm);
printf("Enter total kilometers traveled:\n");
scanf("%f", &kilometers);
printf("Enter waiting time charge:\n");
scanf("%f", &waitingCharge);
totalFare = baseFare + (costPerKm * kilometers) + waitingCharge;
printf("\nTotal Taxi Fare = %.2f\n", totalFare);
return 0;
}
Print-screen of the output:
Question 3
Code:
#include <stdio.h>
int main() {
float weight, height, bmi;
printf("Enter weight in kg:\n");
scanf("%f", &weight);
printf("Enter height in meters:\n");
scanf("%f", &height);
bmi = weight / (height * height);
printf("\nBMI = %.2f\n", bmi);
if (bmi < 18.5) {
printf("Category: Underweight\n");
}
else if (bmi < 25) {
printf("Category: Normal\n");
}
else if (bmi < 30) {
printf("Category: Overweight\n");
}
else {
printf("Category: Obese\n");
}
return 0;
}
Print-screen of the output:
Question 4
Code:
#include <stdio.h>
int main() {
int customertype;
float usage, bill;
while (1) {
printf("\nEnter customer type (1-Residential, 2-Commercial, 3-Industrial, 0 to
exit): ");
if (scanf("%d", &customertype) != 1) {
printf("Invalid input. Program terminated.\n");
break;
}
if (customertype == 0) {
printf("Program terminated.\n");
break;
}
printf("Enter usage (in kWh): ");
if (scanf("%f", &usage) != 1) {
printf("Invalid input. Program terminated.\n");
break;
}
bill = 0;
switch (customertype) {
case 1:
bill = 10 + (usage * 4);
printf("Residential Customer Bill: ₺%.2f\n", bill);
break;
case 2:
bill = 20 + (usage * 2);
printf("Commercial Customer Bill: ₺%.2f\n", bill);
break;
case 3:
if (usage <= 100) {
bill = usage * 3;
} else {
bill = (100 * 3) + ((usage - 100) * 2);
}
printf("Industrial Customer Bill: ₺%.2f\n", bill);
break;
default:
printf("Invalid customer type. Please try again.\n");
}
}
return 0;
}
Print-screen of the output:
Question 5
Code:
#include <stdio.h>
int sumOfSquares(int n) {
int sum = 0, digit;
while (n > 0) {
digit = n % 10;
sum += digit * digit;
n /= 10;
}
return sum;
}
int isHappy(int n) {
int slow = n, fast = n;
do {
slow = sumOfSquares(slow);
fast = sumOfSquares(sumOfSquares(fast));
} while (slow != fast);
return (slow == 1);
}
void showSteps(int n) {
int seen = 0;
printf("\nSteps for %d:\n", n);
while (n != 1 && seen < 10) {
printf("%d -> ", n);
n = sumOfSquares(n);
seen++;
}
printf("%d\n", n);
}
int main() {
int i;
printf("Happy numbers between 1 and 1000:\n");
for (i = 1; i <= 1000; i++) {
if (isHappy(i)) {
printf("%d ", i);
}
}
showSteps(70);
showSteps(103);
printf("\n");
return 0;
}
Print-screen of the output: