Assignment-1
SET-A:
1. Write a C Program to Find the Size of int, float, double, and char
#include <stdio.h>
int main()
{
printf("Size of int: %d bytes\n", sizeof(int));
printf("Size of float: %d bytes\n", sizeof(float));
printf("Size of double: %d bytes\n", sizeof(double));
printf("Size of char: %d byte\n", sizeof(char));
return 0;
}
2. C Program to Calculate the Area of a Circle
#include <stdio.h>
#define PI 3.14159
int main()
{
float radius, area;
printf("Enter the radius of the circle: ");
scanf("%f", &radius);
area = PI * radius * radius;
printf("Area of the circle = %f\n", area);
return 0;
}
3. C Program to Calculate the Area of a Square
#include <stdio.h>
int main() {
float side, area;
printf("Enter the side of the square: ");
scanf("%f", &side);
area = side * side;
printf("Area of the square = %f\n", area);
return 0;
}
4. C Program to Calculate the Area of a Triangle
#include <stdio.h>
int main() {
float base, height, area;
printf("Enter the base of the triangle: ");
scanf("%f", &base);
printf("Enter the height of the triangle: ");
scanf("%f", &height);
area = 0.5 * base * height;
printf("Area of the triangle = %f\n", area);
return 0;
}
5. C Program to Calculate Simple Interest
#include <stdio.h>
int main() {
float principal, rate, time, simpleInterest;
printf("Enter principal amount: ");
scanf("%f", &principal);
printf("Enter rate of interest (in %%): ");
scanf("%f", &rate);
printf("Enter time (in years): ");
scanf("%f", &time);
simpleInterest = (principal * rate * time) / 100;
printf("Simple Interest = %f\n", simpleInterest);
return 0;
}
SET-B:
1. C Program to Swap Two Numbers Without Using Third Variable
#include <stdio.h>
int main()
{
int a, b;
printf("Enter first number (a): ");
scanf("%d", &a);
printf("Enter second number (b): ");
scanf("%d", &b);
// Swapping without third variable
a = a + b;
b = a - b;
a = a - b;
printf("After swapping: a = %d, b = %d\n", a, b);
return 0;
}
2. C Program to Display ASCII Value of a Character
#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
printf("ASCII value of '%c' is %d\n", ch, (int)ch);
return 0;
}
3. C Program to Convert Fahrenheit to Celsius and Vice Versa
#include <stdio.h>
int main()
{
float temp, celsius, fahrenheit;
int choice;
printf("Choose conversion:\n");
printf("1. Fahrenheit to Celsius\n");
printf("2. Celsius to Fahrenheit\n");
printf("Enter your choice (1 or 2): ");
scanf("%d", &choice);
if (choice == 1) {
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &temp);
celsius = (temp - 32) * 5 / 9;
printf("Temperature in Celsius: %f°C\n", celsius);
} else if (choice == 2) {
printf("Enter temperature in Celsius: ");
scanf("%f", &temp);
fahrenheit = (temp * 9 / 5) + 32;
printf("Temperature in Fahrenheit: %f°F\n", fahrenheit);
} else {
printf("Invalid choice.\n");
}
return 0;
}
4. C Program to Calculate Distance Between Two Points
#include <stdio.h>
#include <math.h>
int main()
{
float x1, y1, x2, y2, distance;
printf("Enter coordinates of first point (x1 y1): ");
scanf("%f %f", &x1, &y1);
printf("Enter coordinates of second point (x2 y2): ");
scanf("%f %f", &x2, &y2);
distance = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
printf("Distance between the two points = %f\n", distance);
return 0;
}
SET-C:
The basic salary of an employee is decided at the time of employment, which may be
different for different employees. Apart from basic, employee gets 10% of basic as
houserent, 30% of basic as dearness allowance. A professional tax of 5% of basic is
deducted from salary. Accept the employee id and basic salary for an employee and output
the take home salary of the employee.
#include <stdio.h>
int main()
int emp_id;
float basic, house_rent, dearness_allowance, professional_tax, take_home;
// Accept employee ID and basic salary
printf("Enter Employee ID: ");
scanf("%d", &emp_id);
printf("Enter Basic Salary: ");
scanf("%f", &basic);
// Calculating components
house_rent = 0.10 * basic;
dearness_allowance = 0.30 * basic;
professional_tax = 0.05 * basic;
// Calculating take home salary
take_home = basic + house_rent + dearness_allowance - professional_tax;
// Output
printf("\n--- Salary Slip ---\n");
printf("Employee ID: %d\n", emp_id);
printf("Basic Salary: %f\n", basic);
printf("House Rent (10%): %f\n", house_rent);
printf("Dearness Allowance (30%): %f\n", dearness_allowance);
printf("Professional Tax (5%): %f\n", professional_tax);
printf("Take Home Salary: %f\n", take_home);
return 0;