10/5/23, 8:07 PM Assignment 1 part A module 1 - Colaboratory
Assign integer , float and character data to the variable radius, area, shape and display
%%file intflochar.c
#include<stdio.h>
int main()
{
int radius = 6;
float area = 56.9;
char shape = 'C';
printf("Radius: %d\n", radius);
printf("Area: %.2f\n", area);
printf("Shape: %c\n", shape);
return 0;
}
Overwriting intflochar.c
!gcc intflochar.c
!./a.out
Radius: 6
Area: 56.90
Shape: C
b. Read some input for the following variable and display
angle , side, length (integer type)
%%file parta.c
#include<stdio.h>
int main()
{
int Angle, side, Length;
printf("enter the value of angle (degrees):");
scanf("%d", &Angle);
printf("enter the value for side (cm): ");
scanf("%d", &side);
printf("Enter the value for Length (cm): ");
scanf("%d", &Length);
printf("Angle: %d degrees\n", Angle);
printf("Side: %d cm\n", side);
printf("Length: %d cm\n", Length);
return 0;
}
Overwriting parta.c
!gcc parta.c
!./a.out
enter the value of angle (degrees):90
enter the value for side (cm): 78
Enter the value for Length (cm): 90
Angle: 90 degrees
Side: 78 cm
Length: 90 cm
area, salary, emi, bankbalance (float type)
%%file parta.c
#include <stdio.h>
int main()
{
float length, width, salary, emi, bankBalance;
// Read input
https://colab.research.google.com/drive/1242GpDrasjh4bwahUR_OvikUCPpoh1_v#scrollTo=TpuXTac1P6RN&printMode=true 1/8
10/5/23, 8:07 PM Assignment 1 part A module 1 - Colaboratory
printf("Enter length of rectangle: ");
scanf("%f", &length);
printf("Enter width of rectangle: ");
scanf("%f", &width);
printf("Enter salary: ");
scanf("%f", &salary);
printf("Enter EMI: ");
scanf("%f", &emi);
printf("Enter bank balance: ");
scanf("%f", &bankBalance);
// Calculate area of rectangle
float area = length * width;
// Display results
printf("Area of rectangle: %.2f\n", area);
printf("Salary: %.2f\n", salary);
printf("EMI: %.2f\n", emi);
printf("Bank Balance: %.2f\n", bankBalance);
return 0;
}
Overwriting parta.c
!gcc parta.c
!./a.out
Enter length of rectangle: 5.7
Enter width of rectangle: 8.9
Enter salary: 100000
Enter EMI: 2000
Enter bank balance: 200000
Area of rectangle: 50.73
Salary: 100000.00
EMI: 2000.00
Bank Balance: 200000.00
grade, gender,flag,lightstatus (character type)
%%file parta.c
#include <stdio.h>
int main() {
char grade, gender, flag, lightStatus;
// Read input
printf("Enter your grade (A/B/C): ");
scanf(" %c", &grade);
printf("Enter your gender (M/F): ");
scanf(" %c", &gender);
printf("Enter a flag character (0/#/4): ");
scanf(" %c", &flag);
printf("Enter light status (Red/Green/Yellow): ");
scanf(" %c", &lightStatus);
// Display the input values
printf("Grade: %c\n", grade);
printf("Gender: %c\n", gender);
printf("Flag: %c\n", flag);
printf("Light Status: %c\n", lightStatus);
return 0;
}
Overwriting parta.c
!gcc parta.c
!./a.out
Enter your grade (A/B/C): A
Enter your gender (M/F): F
Enter a flag character (0/#/4): 0
https://colab.research.google.com/drive/1242GpDrasjh4bwahUR_OvikUCPpoh1_v#scrollTo=TpuXTac1P6RN&printMode=true 2/8
10/5/23, 8:07 PM Assignment 1 part A module 1 - Colaboratory
Enter light status (Red/Green/Yellow): Red
Grade: A
Gender: F
Flag: 0
Light Status: R
Write a C program to evaluate the following expressions.
a.45+45/7-45%7
%%file parta.c
#include <stdio.h>
int main() {
int result;
result = 45 + 45 / 7 - 45 % 7;
printf("Result: %d\n", result);
return 0;
}
Overwriting parta.c
!gcc parta.c
!./a.out
Result: 48
Write a C program to evaluate the following expressions b. (33-9+7)5/9
%%file parta.c
#include <stdio.h>
int main() {
int result;
result = (33-9+7);5/9;
printf("Result: %d\n", result);
return 0;
}
Overwriting parta.c
!gcc parta.c
!./a.out
Result: 31
Write a C program to evaluate the following expressions. c. 5-4+2*9/11%3
%%file parta.c
#include <stdio.h>
int main() {
int result;
result = 5-4+2*9/11%3;
printf("Result: %d\n", result);
return 0;
}
Overwriting parta.c
!gcc parta.c
!./a.out
https://colab.research.google.com/drive/1242GpDrasjh4bwahUR_OvikUCPpoh1_v#scrollTo=TpuXTac1P6RN&printMode=true 3/8
10/5/23, 8:07 PM Assignment 1 part A module 1 - Colaboratory
Result: 2
Write a C program to evaluate the following expressions. d. 2+4+5^2+1+4^3
%%file parta.c
#include <stdio.h>
int main() {
int result;
result = 2+4+5^2+1+4^3;
printf("Result: %d\n", result);
return 0;
}
Overwriting parta.c
!gcc parta.c
!./a.out
Result: 15
Write a C program to evaluate the following expressions. a. a+b/c-d%e
%%file parta.c
#include <stdio.h>
int main() {
int a, b, c, d, e;
int result;
// Input values for a, b, c, d, and e
printf("Enter the value of a: ");
scanf("%d", &a);
printf("Enter the value of b: ");
scanf("%d", &b);
printf("Enter the value of c: ");
scanf("%d", &c);
printf("Enter the value of d: ");
scanf("%d", &d);
printf("Enter the value of e: ");
scanf("%d", &e);
result = a + b / c - d % e;
printf("Result: %d\n", result);
return 0;
}
Overwriting parta.c
!gcc parta.c
!./a.out
Enter the value of a: 6
Enter the value of b: 9
Enter the value of c: 10
Enter the value of d: 8
Enter the value of e: 6
Result: 4
Write a C program to evaluate the following expressions. TotalMarks-NegativeMakrs+2*BonusMakrs
https://colab.research.google.com/drive/1242GpDrasjh4bwahUR_OvikUCPpoh1_v#scrollTo=TpuXTac1P6RN&printMode=true 4/8
10/5/23, 8:07 PM Assignment 1 part A module 1 - Colaboratory
%%file parta.c
#include <stdio.h>
int main() {
int Totalmarks, negativemarks, Bonusmarks;
int result;
// Input values for Totalmarks, negativemarks, and Bonusmarks
printf("Enter Totalmarks: ");
scanf("%d", &Totalmarks);
printf("Enter negativemarks: ");
scanf("%d", &negativemarks);
printf("Enter Bonusmarks: ");
scanf("%d", &Bonusmarks);
// Evaluate the expression
result = Totalmarks - negativemarks + 2 * Bonusmarks;
// Display the result
printf("Result: %d\n", result);
return 0;
}
Overwriting parta.c
!gcc parta.c
!./a.out
Enter Totalmarks: 200
Enter negativemarks: 40
Enter Bonusmarks: 10
Result: 180
p+q+r^s+t+u^v
%%file parta.c
#include <stdio.h>
int main() {
int p, q, r, s, t, u, v;
int result;
printf("Enter the value of p: ");
scanf("%d", &p);
printf("Enter the value of q: ");
scanf("%d", &q);
printf("Enter the value of r: ");
scanf("%d", &r);
printf("Enter the value of s: ");
scanf("%d", &s);
printf("Enter the value of t: ");
scanf("%d", &t);
printf("Enter the value of u: ");
scanf("%d", &u);
printf("Enter the value of v: ");
scanf("%d", &v);
result = p+q+r^s+t+u^v;
printf("Result: %d\n", result);
return 0;
}
Overwriting parta.c
https://colab.research.google.com/drive/1242GpDrasjh4bwahUR_OvikUCPpoh1_v#scrollTo=TpuXTac1P6RN&printMode=true 5/8
10/5/23, 8:07 PM Assignment 1 part A module 1 - Colaboratory
!gcc parta.c
!./a.out
Enter the value of p: 2
Enter the value of q: 4
Enter the value of r: 2
Enter the value of s: 4
Enter the value of t: 7
Enter the value of u: 3
Enter the value of v: 2
Result: 4
write a c program to compute a. area of circle
%%file parta.c
#include <stdio.h>
int main() {
double radius;
double area;
printf("Enter the radius of the circle: ");
scanf("%lf", &radius);
// Calculate the area of the circle (π * r * r)
area = 3.14 * radius * radius;
printf("The area of the circle with radius %.2lf is %.2lf\n", radius, area);
return 0;
}
Overwriting parta.c
!gcc parta.c
!./a.out
Enter the radius of the circle: 50
The area of the circle with radius 50.00 is 7850.00
area of square
%%file parta.c
#include <stdio.h>
int main()
{
double side;
double area;
printf("Enter the side of the square: ");
scanf("%lf", &side);
// Calculate the area of the square (side * side )
area = side * side;
printf("The area of the square with side %.2lf is %.2lf\n", side , area);
return 0;
}
Overwriting parta.c
!gcc parta.c
!./a.out
Enter the side of the square: 32
The area of the square with side 32.00 is 1024.00
area of rectangle
https://colab.research.google.com/drive/1242GpDrasjh4bwahUR_OvikUCPpoh1_v#scrollTo=TpuXTac1P6RN&printMode=true 6/8
10/5/23, 8:07 PM Assignment 1 part A module 1 - Colaboratory
%%file parta.c
#include <stdio.h>
int main() {
double length, width;
double area;
printf("Enter the length of the rectangle: ");
scanf("%lf", &length);
printf("Enter the width of the rectangle: ");
scanf("%lf", &width);
// Calculate the area of the rectangle (length * width)
area = length * width;
printf("The area of the rectangle with length %.2lf and width %.2lf is %.2lf\n", length, width, area);
return 0;
}
Overwriting parta.c
!gcc parta.c
!./a.out
Enter the length of the rectangle: 34
Enter the width of the rectangle: 23
The area of the rectangle with length 34.00 and width 23.00 is 782.00
iv. Calculate simple interest
%%file parta.c
#include <stdio.h>
int main()
{
double principal, rate, time, interest;
printf("Enter the principal amount: ");
scanf("%lf", &principal);
printf("Enter the rate of interest (in percentage): ");
scanf("%lf", &rate);
printf("Enter the time (in years): ");
scanf("%lf", &time);
// Calculate simple interest (principal * rate * time / 100)
interest = (principal * rate * time) / 100.0;
printf("Simple Interest: %.2lf\n", interest);
return 0;
}
Overwriting parta.c
!gcc parta.c
!./a.out
Enter the principal amount: 40000
Enter the rate of interest (in percentage): 7
Enter the time (in years): 2
Simple Interest: 5600.00
Read two angle of a triangle and find third angle
%%file parta.c
https://colab.research.google.com/drive/1242GpDrasjh4bwahUR_OvikUCPpoh1_v#scrollTo=TpuXTac1P6RN&printMode=true 7/8
10/5/23, 8:07 PM Assignment 1 part A module 1 - Colaboratory
#include <stdio.h>
int main()
{
float angle1, angle2, angle3;
printf("Enter the first angle of the triangle: ");
scanf("%f", &angle1);
printf("Enter the second angle of the triangle: ");
scanf("%f", &angle2);
// Calculate the third angle using the formula: angle3 = 180 - (angle1 + angle2)
angle3 = 180 - (angle1 + angle2);
printf("The third angle of the triangle is: %.2f degrees\n", angle3);
return 0;
}
Overwriting parta.c
!gcc parta.c
!./a.out
Enter the first angle of the triangle: 20
Enter the second angle of the triangle: 40
The third angle of the triangle is: 120.00 degrees
https://colab.research.google.com/drive/1242GpDrasjh4bwahUR_OvikUCPpoh1_v#scrollTo=TpuXTac1P6RN&printMode=true 8/8