LAB1 Students
LAB1 Students
For checking gcc version and verify if gcc is installed cd .. [for getting out from
properly on the machine existing folder]
gcc --version
cd Desktop/ [for getting
If gcc is not installed, into Desktop folder]
sudo apt update
ll or ls [list all the files &
sudo apt install build-essential folders in the existing
folder]
For compiling .c file to an executable
gcc sample.c -o sample
Input:
Let the input be 2 integers stored as A and B
Output:
Display C
Operations:
Let C be an integer C such that
C =A +B
Specify the Including Standard Input output header file
preprocessor directive
Main function main() is the entry point of every C program. No other code will
Return type execute before and after main()
LHS_Value= RHS_Value
LHS_Value signifies address
RHS_Value signifies value.
Value at RHS is assigned to Address of LHS
int X= 10;
Value assigned
10
Address of X
X
RAM
int Y = X+2;
12
Value of X Y
Address of Y
Arithmetic Operators(Binary Operators, since two operands)
•+
• -
• *
• / (Quotient of division)
5/2 = 2 Integer division, since both operands are integers
5.4/2 =5.4/2.0 =2.7 Result is float division since one of the operand is float.
• %(modulus)
If a> b then a%b gives remainder of a/b
If a <b then a%b gives a
If a=b then a%b gives 0
Type Conversion
Implicit Type Conversion When lower data type gets int X= 3;
operated with higher data float Y=X;
type then lower data type //output: Y=3.0
gets implicitly converted to
higher data type.
No loss of precision.
Explicit Type Conversion When we need to convert float X=3.2;
higher data type to lower data int Y= (int) X;
type then explicit type //output: Y=3
conversion/ type casting is
required. General format:
(target_type) identifier
Loss of precision.
• Relational Operators • ShortHand Assignment Operators
< += i.e a+=b a=a+b
<= -= i.e a-=b a=a-b
> *= i.e a*=b a=a*b
>= /= i.e a/=b a=a/b
Returns Boolean value(1 bit) %= i.e a%=b a=a%b
i.e either True or False
• Equality Operators
== Equal to
!= Not equal to
Returns Boolean value(1 bit)
i.e either True or False
Lab1: Use the formatted input/output statements,
operators and expressions of C language
A: Write a C program to input 2 numbers. Perform addition, subtraction,
multiplication, division and modulus and display output.
B: WAP to Convert Celsius to Fahrenheit. Answer should be rounded upto 2
decimal places
fahrenheit=(celsius×9/5)+32
C: WAP to Convert Foot to Meter. Answer should be rounded upto 3 decimal
places
meter=foot×0.3048
D: Write a C program to convert days into year, month and days.
double a function that returns the smallest integer value
⌈x⌉
ceil(double x) greater than or equal to x in type double
double a function that returns the largest integer value less
⌊x⌋
floor(double x) than or equal to x in type double
double a function that evaluates the absolute value of x in
IxI
fabs(double) type double
F: Write a C program to calculate the CGPI based on subject marks (each subject
out of 100) and attendance for each subject. The program should take input for
the marks of each subject and whether attendance for that subject is above or
below 75%:
•Input 0 if attendance is less than 75% for a subject.
•Input 1 if attendance is greater than or equal to 75% for a subject.
•If the attendance is below 75% for a subject (i.e., input is 0), the program should
ignore the marks for that subject and consider them as 0 when calculating the
CGPI.
Lab1B: H-Division
E: Write a C program to calculate the Euclidean distance between two points in a
2D plane. The user provides the coordinates of two points (x1,y1) and (x2,y2).
F. Write a C program that accepts two numbers from the user and swaps their
values. The program should demonstrate two methods for swapping:
1.Using a third variable.
2.Without using a third variable.( use shorthand operators if possible)
Lab1B: E-Division
E: Write a C program that calculates the surface area and volume of a
cylinder. The program should demonstrate two methods for obtaining
the value of π (Pi):
• Using a macro for Pi.
• Using the existing M_PI constant from the math.h library.
TA=15%of basic
DA=90% of basic
HRA=20% of basic
Gross=Basic+ TA+HRA+DA
• https://www.scaler.com/topics/c/math-h-functions-in-c/