MAT09-Example Exercises (Week 8)
MAT09-Example Exercises (Week 8)
int main()
{
Expected Output: printf("Name : Alexandra Abramov\n");
Name : Alexandra Abramov
printf("DOB : July 14, 1975\n");
DOB : July 14, 1975
Mobile : 99-9999999999 printf("Mobile : 99-9999999999\n");
return 0;
}
printf("The reverse of %c%c%c is %c%c%c\n", char1, char2, char3, char3, char2, char1);
return 0;
}
4. Write a C program to compute the perimeter and area of a rectangle with a height of 7
inches. and width of 5 inches.
Expected Output:
Perimeter of the rectangle = 24 inches
Area of wthe rectangle = 35 square inches
#include <stdio.h>
int main() {
/* height and width of a rectangle in inches */
int width, height;
int area, perimeter;
height = 7;
width = 5;
return 0;
}
5. Write a C program to compute the perimeter and area of a circle with a given radius.
Expected Output:
Perimeter of the Circle = 37.680000 inches
Area of the Circle = 113.040001 square inches
#include <stdio.h>
int main() {
int radius;
float area, perimeter;
radius = 6;
perimeter = 2*3.14*radius;
printf("Perimeter of the Circle = %f inches\n", perimeter);
area = 3.14*radius*radius;
printf("Area of the Circle = %f square inches\n", area);
return 0;
}
a + c = 212
x + c = 89.134590
dx + x = 3.276183
((int) dx) + ax = 1234567891
a + x = 127.134590
s + b = 16388
ax + b = 1234580235
s + c = 4130
ax + c = 1234567977
ax + ux = 3776135780
#include <stdio.h>
int main()
{
int a = 125, b = 12345;
long ax = 1234567890;
short s = 4043;
float x = 2.13459;
double dx = 1.1415927;
char c = 'W';
unsigned long ux = 2541567890;
return 0;
}
7. Write a C program to convert specified days into years, weeks and days.
(Note: Ignore leap year. You can also change the test data to check if the desired output
is attained)
Test Data:
Number of days : 1329
Expected Output :
Years: 3
Weeks: 33
Days: 3
#include <stdio.h>
int main()
{
int days, years, weeks;
days = 1329;
return 0;
}
8. Write a C program that accepts two integers from the user and calculate the sum of the
two integers.
Test Data :
Input the first integer: 25
Input the second integer: 38
Expected Output:
Sum of the above two integers = 63
#include <stdio.h>
int main()
{
int x, y, sum;
printf("\nInput the first integer: ");
scanf("%d", &x);
printf("\nInput the second integer: ");
scanf("%d", &y);
sum = x + y;
printf("\nSum of the above two integers = %d\n", sum);
return 0;
}
9. Write a C program that accepts two integers from the user and calculate the product of
the two integers.
Test Data :
Input the first integer: 25
Input the second integer: 15
Expected Output:
Product of the above two integers = 375
#include <stdio.h>
int main()
{
int x, y, result;
printf("\nInput the first integer: ");
scanf("%d", &x);
printf("\nInput the second integer: ");
scanf("%d", &y);
result = x * y;
printf("Product of the above two integers = %d\n", result);
return 0;
}
10. Write a C program that accepts two item’s weight (floating points' values ) and number of
purchase (floating points' values) and calculate the average value of the items.
Test Data :
#include <stdio.h>
Weight - Item1: 15 int main()
No. of item1: 5 {
Weight - Item2: 25 double wi1, ci1, wi2, ci2, result;
No. of item2: 4 printf("Weight - Item1: ");
Expected Output: scanf("%lf", &wi1);
Average Value = 19.444444 printf("No. of item1: ");
scanf("%lf", &ci1);
printf("Weight - Item2: ");
scanf("%lf", &wi2);
printf("No. of item2: ");
scanf("%lf", &ci2);
result = ((wi1 * ci1) + (wi2 * ci2)) / (ci1 + ci2);
printf("Average Value = %f\n", result);
return 0;
}