C Programming Lab Student Manual
C Programming Lab Student Manual
AIM:
To write a C program to calculate the areas of different shapes, namely circle,
rectangle and triangle using Input and Output Statements.
OBJECTIVES:
● To understand the concept of input output statements such as formatted and
unformatted.
DESCRIPTION(Mapping to Theory):
The C programming language is equipped with built-in functions,
specifically printf() and scanf() which are used for performing formatted output
and input operations respectively. These functions are termed as 'formatted'
because they allow data to be inputted or outputted in a specific, predetermined
format.
Formatted I/O functions
The formatted functions accept various format specification strings along
with a list of variables in the form of parameters. This format specification string
refers to a character string used for specifying the data type of every variable
present as the output or input along with the width and size of the I/O.The C
program performs input and output operations using different input and output
functions.
printf():The printf function is used to print formatted output to the console.
Control String: A format string that specifies how subsequent arguments (if any)
are converted for output.Additional arguments to be formatted and printed.
scanf():The scanf function is used to read formatted input from the console.
These functions are used exclusively for character data types or character
arrays/strings. They are designed for reading single inputs from the user at the
console and for displaying values on the console.They are referred to as
“unformatted” I/O functions because they do not support format specifiers. Unlike
formatted I/O functions like printf() and scanf(), you cannot use format specifiers
to control the formatting of the data. They display or read data as-is without
formatting options.
1. getch()
2. getchar()
3. putchar()
4. gets()
5. puts()
6. putch()
getchar():In C, getchar() reads a single character from the keyboard and waits
until the Enter key is pressed. It processes one character at a time. This function is
declared in the stdio.h header file
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
Syntax: putchar(variable_name);
gets(): In C, gets() reads a group of characters or strings from the keyboard, and
these characters are stored in a character array. It allows you to input space-
separated texts or strings. This function is declared in the stdio.h header file.
However, please note that gets() is considered unsafe due to the risk of buffer
overflow and is generally discouraged in favor of safer alternatives like fgets().
Example:gets(str);
Syntax: puts(identifier_name );
Syntax: putch(variable_name);
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
SOFTWARE REQUIRED:
ALGORITHM:
PSEUDOCODE:
BEGIN
INPUT length, breadth,radius,base, height
SET a1 = length * breadth
SET a2 = 0.5 * base * height
SET a3 = 3.14 * radius * radius
OUTPUT a1
OUTPUT a2
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
OUTPUT a3
END
FLOWCHART:
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
VIVA QUESTIONS
1. How do you calculate the area of different shapes?
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
RESULT:
Hence, the C-program to calculate the areas of different shapes was successfully
executed.
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
AIM:
To write a C program of Greatest of three numbers using Operators and
Conditional statements.
OBJECTIVES:
DESCRIPTION(Mapping to Theory):
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
CONDITIONAL STATEMENTS:
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
Syntax:
if(condition)
{
// true statement(s)
}
else if (Condition)
{
// elseif True Statements
}
else
{
//False Statement
}
If...Else (Ternary Operator),There is also a short-hand if else, which is known as
the ternary operator because it consists of three operands. It can be used to replace
multiple lines of code with a single line. It is often used to replace simple if else
statements:
Syntax: variable = (condition) ? expressionTrue : expressionFalse;
ALGORITHM:
Step1:Start
Step2:Declare appropriate variables, a, b, c for the respective
three numbers as integers.
Step3:Obtain inputs of the three numbers.
Step4:Using conditional if and logical AND, check
if a>b && a>c then go to Step 4.1, else go to step 5.
Step 4.1 Print a is the largest number.
Step5:Using conditional if and logical AND,
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
PSEUDOCODE:
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
FLOWCHART:
Use if-else statements to handle different ranges of sensor data and trigger
appropriate actions.
2. Engine Control:
Use if statements to adjust engine parameters based on conditions like speed and
temperature.
3. Transaction Processing
Use if-else statements to validate and process transactions based on different
criteria.
VIVA QUESTIONS:
1. What is the purpose of the if statement in C?
2. How does the if-else construct differ from the if-else if-else construct?
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
OBJECTIVES:
To understand the concept of using a for loop.
DESCRIPTION(Mapping to Theory):
The for loop is a control flow statement for specifying iteration. Specifically,
a for-loop functions by running a section of code repeatedly until a certain
condition has been satisfied. In the for loop, the variable i is initialized to 1, and the
loop will continue as long as i is less than or equal to 10. In each iteration of the
loop, the printf function will print the value of i to the console, followed by a space
character. Finally, the loop will increment the value of i by 1, and the process will
repeat until the condition i<=10 is no longer true.So, when this code runs, it will
output the numbers 1 through 10 separated by spaces.
SYNTAX:
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
2. During the Second Step condition statements are checked and only if the
condition is the satisfied loop we can further process otherwise the loop is
broken.
4: Updating the values of variables has been done as defined in the loop.
Continue to Step 2 till the loop breaks.
Algorithm:
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
Pseudo Code:
FLOWCHART:
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024
U24CS101 Programming in C STUDENT LAB MANUAL
RESULT: Hence the C-program to the first 10 natural numbers was successfully
executed and the Output was verified.
Department:CSE/IT/AIDS/EEE/ECE MSEC
R2024