Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

CS101 Introduction to Programming

Computer Lab
Arithmetic Operations

1. Write a program that follows the below instructions:


1. Declare a variable "a" of type integer, and initialize its value with 12
2. Declare a variable "b" of type integer, and initialize its value with 7
3. Declare a variable "c" of type integer, and initialize its value with 0
4. Assign the sum of "a" and "b" to the variable c
5. Print the “a”, “b” & “c”variable in a formatted manner.
Add a newline at the end.
Declare a variable "d" of type integer, and initialize its value with (a - b)
g. Print the "d" variable in a formatted manner.

# include <stdio.h>
# include <Stdlib.h>
Int main()

{
Int a=12;
Int b=7;
Int c=0;
Int c=a+b;
Int d=a-b;
Printf(“a%d,b%d,c%d/n,d%d”,a,b,c,d);

Return 0
}

2. Write a program that follows the bellow instructions:


1. Declare a variable "a" of type float, and initialize its value with 2.6
2. Declare a variable "b" of type float, and initialize its value with 3
3. Declare a variable "m" of type float, and initialize its value with O
4. Assign the multiplication of "a" by "b" to the variable "m"
a. Print the different variables values in a formatted manner. The float value should have 2 degree of precision

# include <stdio.h>
# include <Stdlib.h>
Int main()

{
Float a=2.6;
Float b=3;
Float m=0;
Float m=a*b;
Printf(“a%2f,b=%2f,m=%2f\n”,a,b,m);

Return 0
}

3. Write a program that follows the bellow instructions:


1. Declare a variable "a" of type integer, and initialize its value with 100
2. Declare a variable "b" of type integer, and initialize its value with 3
3. Declare a variable "sum" of type integer, and initialize its value with (a + b)
4. Declare a variable "average" of type float, and initialize its value with 0.
5. Divide the "sum" by 2 and assign the result to "average" variable.
6. Print the different variables values in a formatted manner.
7. Fix the division operation of "sum" by 2 so that we have a correct value in
"average"

# include <stdio.h>
# include <Stdlib.h>
Int main()
{
int a=100;
int b= 3;
int sum=a+b;
Float average= 0;
Average =sum/2
- sum
Phant areas: 0 / 2

You might also like