You are on page 1of 11

LAB – RECORD

iOS App Prototype Design and Development


(Subject Code: 18CSV411l)

B.TECH (CSE) – III YEAR / VI SEMESTER

Name: Shreya Bajaj


Reg. No.: RA2011003030029

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

SRM INSTITUTE OF SCIENCE & TECHNOLOGY,


DELHI – NCR CAMPUS, MODINAGAR
(SIKRI KALAN, DELHI MEERUT ROAD, DIST. – GHAZIABAD – 201204)
www.srmimt.net
____________________________

Even Semester (2022 – 2023)


ASSIGNMENT - 1
1. Program to calculate the total and average of marks of 5 subjects.
Program:-
#include <stdio.h>
int main() {
float marks[5], total = 0, avg;
printf("Enter marks of 5 subjects:\n");
for (int i = 0; i < 5; i++) {
printf("Subject %d: ", i + 1);
scanf("%f", &marks[i]);
total += marks[i];
}
avg = total / 5;
printf("Total marks = %.2f\n", total);
printf("Average marks = %.2f\n", avg);
return 0;
}
Output:-

2. Program to calculate the quotient and remainder of a number


Program:-
#include <stdio.h>
int main() {
int num, divisor, quotient, remainder;
printf("Enter a number: ");
scanf("%d", &num);
printf("Enter a divisor: ");
scanf("%d", &divisor);
quotient = num / divisor;
remainder = num % divisor;
printf("Quotient = %d\n", quotient);
printf("Remainder = %d\n", remainder);
return 0;
}
Output:-

3. Program to print the ASCII code of a character.


Program:-
#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);
printf("ASCII code of '%c' is %d\n", c, c);
return 0;
}
Output:-

4. Program to calculate the product of two floating numbers


Program:-
#include <stdio.h>
int main() {
float num1, num2, product;
printf("Enter two floating numbers: ");
scanf("%f %f", &num1, &num2);
product = num1 * num2;
printf("Product = %.2f\n", product);
return 0;
}
Output:-
5. Program to convert hours to minutes and seconds
Program:-
#include <stdio.h>
int main() {
int hours, minutes, seconds;
printf("Enter number of hours: ");
scanf("%d", &hours);
minutes = hours * 60;
seconds = hours * 3600;
printf("%d hours = %d minutes\n", hours, minutes);
printf("%d hours = %d seconds\n", hours, seconds);
return 0;
}
Output:-

6. Program to perform swapping of two numbers


Program:-
#include <stdio.h>
int main() {
int num1, num2, temp;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
temp = num1;
num1 = num2;
num2 = temp;
printf("After swapping:\n");
printf("Num1 = %d\n", num1);
printf("Num2 = %d\n", num2);
return 0;
}
Output:-
7. Program to perform swapping of two numbers using add/sub
operators
Program:-
#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
a = a + b;
b = a - b;
a = a - b;
printf("After swapping, the values of a and b are %d and %d respectively.", a, b);
return 0;
}
Output:-

8. Program to perform swapping of two numbers using mul/div operators


Program:-
#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
a = a * b;
b = a / b;
a = a / b;
printf("After swapping, the values of a and b are %d and %d respectively.", a, b);
return 0;
}
Output:-
9. Program to convert temperature in fahrenheit into degree Celsius
Program:-
#include <stdio.h>
int main() {
float fahrenheit, celsius;
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("%.2f Fahrenheit is equal to %.2f Celsius.", fahrenheit, celsius);
return 0;
}
Output:-

10. Program to convert temperature in celsius into Fahrenheit


Program:-
#include <stdio.h>
int main() {
float fahrenheit, celsius;
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
fahrenheit = (celsius * 9 / 5) + 32;
printf("%.2f Celsius is equal to %.2f Fahrenheit.", celsius, fahrenheit);
return 0;
}
Output:-
11.Program to calculate the area and volume of cone
Program:-
#include <stdio.h>
#include <math.h>
#define PI 3.14159
int main() {
float radius, height, volume, area;
printf("Enter radius and height of the cone: ");
scanf("%f%f", &radius, &height);
volume = (PI * pow(radius, 2) * height) / 3;
area = PI * radius * (radius + sqrt(pow(height, 2) + pow(radius, 2)));
printf("Volume of the cone is %.2f cubic units.\n", volume);
printf("Total surface area of the cone is %.2f square units.", area);
return 0;
}
Output:-

12.Program to calculate the area and volume of cylinder


Program:-
#include <stdio.h>
#include <math.h>
#define PI 3.14159
int main() {
float radius, height, volume, area;
printf("Enter radius and height of the cylinder: ");
scanf("%f%f", &radius, &height);
volume = PI * pow(radius, 2) * height;
area = 2 * PI * radius * (height + radius);
printf("Volume of the cylinder is %.2f cubic units.\n", volume);
printf("Total surface area of the cylinder is %.2f square units.", area);
return 0;
}
Output:-
13.Program to calculate the area and volume of a sphere:
Program:-
#include<stdio.h>
#define PI 3.14
int main() {
float radius, volume, surface_area;
printf("Enter the radius of the sphere: ");
scanf("%f", &radius);
// Calculation of volume of sphere
volume = (4.0/3.0) * PI * radius * radius * radius;
printf("Volume of the sphere is: %.2f cubic units\n", volume);
// Calculation of surface area of sphere
surface_area = 4 * PI * radius * radius;
printf("Surface area of the sphere is: %.2f square units\n", surface_area);
return 0;
}
Output:-

14.Program to convert days into year, months, weeks and remaining days:
Program:-
#include<stdio.h>
int main() {
int days, year, month, week, remaining_days;
printf("Enter the number of days: ");
scanf("%d", &days);
year = days / 365;
month = (days % 365) / 30;
week = ((days % 365) % 30) / 7;
remaining_days = ((days % 365) % 30) % 7;
printf("Years: %d\n", year);
printf("Months: %d\n", month);
printf("Weeks: %d\n", week);
printf("Days: %d\n", remaining_days);
return 0;
}
Output:-
15.Program to convert seconds into hours, minutes and seconds:
Program:-
#include<stdio.h>
int main() {
int seconds, hours, minutes, remaining_seconds;
printf("Enter the number of seconds: ");
scanf("%d", &seconds);
hours = seconds / 3600;
minutes = (seconds % 3600) / 60;
remaining_seconds = (seconds % 3600) % 60;
printf("Hours: %d\n", hours);
printf("Minutes: %d\n", minutes);
printf("Seconds: %d\n", remaining_seconds);
return 0;
}
Output:-

16.Program to print the reverse of a 5 digit number.


Program:-
#include<stdio.h>
int main() {
int number, digit1, digit2, digit3, digit4, digit5;
printf("Enter a five-digit number: ");
scanf("%d", &number);
digit1 = number / 10000;
digit2 = (number % 10000) / 1000;
digit3 = (number % 1000) / 100;
digit4 = (number % 100) / 10;
digit5 = number % 10;
printf("The reversed number is: %d%d%d%d%d\n", digit5, digit4, digit3, digit2, digit1);
return 0;
}
Output:-
17.Program to print the sum of reverse digits of a number
Program:-
#include<stdio.h>
int main() {
int number, reverse = 0, remainder, sum = 0;
printf("Enter a number: ");
scanf("%d", &number);
while(number != 0) {
remainder = number % 10;
reverse = reverse * 10 + remainder;
number /= 10;
}
while(reverse != 0) {
remainder = reverse % 10;
sum += remainder;
reverse /= 10;
}
printf("Sum of reverse digits is: %d\n", sum);
return 0;
}
Output:-

18.Write a program to print the sum of first and last digits of a four digit
number
Program:-
#include <stdio.h>
int main()
{
int num, first_digit, last_digit, sum;
// taking user input for the four-digit number
printf("Enter a four-digit number: ");
scanf("%d", &num);
// extracting the first and last digits
last_digit = num % 10;
first_digit = num / 1000;
// calculating the sum
sum = first_digit + last_digit;
// printing the result
printf("The sum of first and last digits of %d is %d\n", num, sum);
return 0;
}
Output:-

19.Write a program to calculate the simple interest


Program:-
#include <stdio.h>
int main()
{
float principal, rate, time, simple_interest;
// taking user input for principal, rate, and time
printf("Enter the principal amount: ");
scanf("%f", &principal);
printf("Enter the rate of interest: ");
scanf("%f", &rate);
printf("Enter the time period (in years): ");
scanf("%f", &time);
// calculating the simple interest
simple_interest = (principal * rate * time) / 100;
// printing the result
printf("Simple Interest = Rs. %.2f\n", simple_interest);
return 0;
}
Output:-

You might also like