LAB 5: Arithmetic Operators, Compound Assignments & Escape Sequence
LAB 5: Arithmetic Operators, Compound Assignments & Escape Sequence
Sequence
Introduction:
In this lab experiment, the students will learn how to use arithmetic operators and
compound assignments and will learn how to use different escape sequences for
formatting and printing different shapes.
Objective:
After completing this lab, the students will be able to have better understanding of
arithmetic operators, compound assignments and escape sequence.
TASK 1:
Write a program that asks the user for their age. Then display what their age would be
five years from now. Then display what their age was five years ago.
#include<stdio.h>
int main()
{
int yourAge = 0;
return 0;
}
TASK 2:
Write a program that prints the following shapes with asterisks. (Use escape
sequences)
int main()
{
printf("*********\t***\t\t*\t\t*\n");
printf("*\t* * \t *\t\t\b\b*****\t\t\b\b\b*\t\t\b\b\b\b\b*\n");
printf("*\t*\t\b\b\b*\t\t\b\b\b*\t\t*\t\t\b\b\b\b*\t\t\b\b\b\b*\n");
printf("*\t*\t\b\b\b*\t\t\b\b\b*\t\t*\t\t\b\b\b\b\b*\t\t\b\b\b*\n");
printf("*\t*\t\b\b\b*\t\t\b\b\b*\t\t*\t\t\b\b\b\b*\t\t\b\b\b\b*\n");
printf("*\t*\t\b\b\b*\t\t\b\b\b*\t\t*\t\t\b\b\b*\t\t\b\b\b\b\b*\n");
return 0;
TASK 3:
Write a program that reads in two integers and determines and prints whether the first is
a multiple of the second. [Hint: Use the remainder operator.]
//determines whether a number is a multiple of the other
#include<stdio.h>
int main()
{
int x, y, z;
z = x % y;
if(z==0)
else
printf("x is not a multiple of y");
return 0;
For x=5,y=7
For x=8,y=2
TASK 4:
Write a program that calculates BMI. You are supposed to take the input weight in kgs
and height in feet and inches. Convert the height in feet and inches entered by user in
meters and calculate the BMI. If your BMI is greater than 25 decrement it by 1. (Use the
decrement operator)
//prints and calculates the BMI
#include<stdio.h>
int main()
For BMI>25
For BMI<25
TASK 5:
Write a program that asks the user to enter to enter a three-digit number, then prints the
number with its digits reversed. A session with the program should have the following
appearance:
Enter a three-digit number: 698
The reversal is: 896
Hint: Use the reminder and division operators to obtain individual digits.
int main()
int num = 0;
int x, y, z;
scanf_s("%d", &num);
x = num / 100;
return 0;
}