Japit-C File
Japit-C File
of
Fundamentals of C Programing
(23CS003)
Submitted in
partial fulfillment for the award of the degree of
BACHELOR OF ENGINEERING
in
Session: 2023-2024
INDEX
S.No. Practical Page No. Date Teacher’s Signature
1. Write a Program to show the use to input (Scanf)/output
(Printf) statements and block structure of C-program by
highlighting the features of "stdio.h".
2. Write a program to add two numbers and display the
sum.
3. Write a program to calculate the area and the
circumference of a circle by using radius as the input
provided by the user.
4. Write a Program to perform addition, subtraction,
division and multiplication of two numbers given as
input by the user.
5. Write a program to evaluate each of the
following equations.
(i) V = u + at. (ii) S = ut+1/2at2 (iii) T=2*a+√b+9c (iv)
H=√b2+p2
6. Write a program to swap two variable:
a) By using temporary variable.
b) Without using temporary variable
7. Write a Program to find the greatest among
three numbers using:
Conditional Operator
If-Else statement
8. Write the following programs using switch case
statement:
To check that an input alphabet is vowel
or consonant
To check whether a number is positive,
negative or zero
9. Write a program using while loop to print the sum of
first n natural numbers.
10. Write a program to check a number is Armstrong or
not using For loop.
11. Write the program to count the digits in a number and
then print the reverse of the number also.
12. Write a program to generate the Fibonacci series.
13. Write a program to print the following
patterns: a)
*
**
***
****
*****
******
b)
*
**
***
****
*****
******
Output:
PSEUDOCODE:
1. Initialize Num
2. Read Num
3. Display “Num”
4. Exit
Coding:
Output:
PSEUDOCODE:
Initialize x and y
Read x and y
Initialize Sum
Compute Sum = x + y
Display “Sum”
Exit
Coding:
Output:
PSEUDOCODE:
Initialize Radius, Area, Circumference
Read Radius
Compute Area = 3.14159 * Radius * Radius
Compute Perimeter = 2 * 3.14159 * Radius
Display “Area” and “Circumference”
Exit
Output:
Output:
PSEUDOCODE:
1. Initialize V, u, a, t as type float
2. Read V, u, a and t using scanf
3. Compute V = u + (a*t)
4. Display “V”
5. Exit.
(ii) S = ut+1/2at2
Coding:
Output:
PSEUDOCODE:
1. Initialize S, u, a and t as type float.
2. Read S, u, a and t
3. Compute S = (u*t) + 0.5*(a*t*t)
4. Display “S”
5. Exit
Coding:
Output:
PSEUDOCODE:
1. Include header file <math.h> for sqrt Function
2. Initialize T, a, b and c as type float.
3. Read the Values for T, a, b and c via scanf.
4. Check for the value b if less than 0 via if-else
condition
5. If 'if’ condition is satisfied print invalid value
6. If ‘else’ condition is satisfied then compute for the
Page | 8 Fundamentals of C programing(23CS003) Japit Singh
value of T
7. Display “T” 2310990612
8. Exit
Program No. – 5(d)
(iii) H=√b2+p2
Coding:
Output:
PSUDEOCODE:
1. Include header file <math.h> for sqrt and pow Function
2. Initialize H, b and p as type float.
3. Read the Values for b and p using scanf
4. Check for the value of ‘b’ and ‘p’ using comparison
operators
5. Using if-else condition print and compute the appropriate
output
6. If ‘if’ condition is satisfied print invalid output.
7. If ‘else’ condition is satisfied compute the value of H and
print it.
8. Display “H”
9. Exit
Coding:
Output:
PSEUDOCODE:
1. Initialize Num1 and Num2 as type int.
2. Initialize a Temporary Variable “Temp” as type int.
3. Read Num1 and Num2
4. Display Num1 and Num2 Before Swap
5. Initialize Temp = Num1
Num1 = Num2
Num2 = Temp
6. Display Num1 and Num2 after Swap.
7. Exit
Coding:
Output:
PSEUDOCODE:
1. Initialize num1 and num2 as type int.
2. Read num1 and num2.
3. (Where num1 is represented by ‘a’ and num2 is represented by
‘b’
4. Display a and b before Swap.
5. Compute:
num1 = num1 + num2
num1 = num1 – num2
num1 = num1 – num2
6. Display num1 and num2 after Swap.
7. Exit Fundamentals of C programing(23CS003)
Page | 12 Japit Singh
2310990612
Program No. – 7(a)
Aim: Write a Program to find the greatest among three numbers using:
Conditional Operator
Coding
Output:
If-Else statement
Coding:
Output:
Coding:
PSEUDOCODE:
1. Include header file <ctype.h> to access toupper Function.
2. (Including this header file isn’t necessary we can check for characters in small case. This is
included to insure uniformity)
3. Initialize Alphabet as type char.
4. Read Alphabet.
5. (Here by using switch case statement we compare the value that the user inputs by putting it
in the switch case and checking it against all the cases. This can also be done with the help
of an if-else condition by putting multiple else if conditions)
6. Switch (Alphabet):
a. Case ‘A’:
Display “A is a Vowel”
Break
b. Case ‘E’:
Display “E is a Vowel”
Break
c. Case ‘I’:
Display “I is a Vowel”
Break
d. Case ‘O’:
Display “O is a Vowel”
Break
e. Case ‘U’:
Display “U is a Vowel”
Break
f. Default:
Display “Consonant”
7. Exit
Coding:
PSEUDOCODE:
Initialize variable Num and sum as int.
Put sum = 0 and in while loop continue till
Num >0.
In while loop increment sum by num while
num is also getting decrement.
Print the sum.
Output:
Program No. – 10
Aim: Write a program to check a number is Armstrong or not using For loop.
PSEUDOCODE:
Initialize variables num,sum,rem,temp as int.
Put temp = num(for comparison).
In while loop(num>0) use % operator to get
the digits one by one and increment it to sum.
Reduce num by using num/10.
Compare sum to temp(if yes ‘armstrong’ else
no.
Print the results
Output:
Program No. - 11
Aim: Write the program to count the digits in a number and then print the reverse of the number also.
Page | 23 Fundamentals of C programing(23CS003) Japit Singh
2310990612
Coding:
Output:
PSEUDOCODE:
Initialize variables count,num,temp as int.
Using a while loop get the reverse of the number and
continue the while loop till num>0 and also get the count.
Using num=num/10
Print the count and the reversed number
Program No. – 12
Output:
PSEUDOCODE:
Initialize the variables num,sum,a,b as int.
Using for loop and algo
(sum= a+b) where values of a and b are being
changed repeatedly
Till the i<num condition is there
Print the series
*
**
***
****
*****
******
Coding:
Output:
PSEUDOCODE:
Initialize variable n(for no of rows).
Using two for loops and correct conditions
(Outer loop i<n+1 ; Inner loop j<i : for stars)
After each loop run print an empty space so to
continue from the next line.
*
**
***
****
*****
Coding:
PSEUDOCODE:
Output:
Initialize variable n(for no of rows).
Using two for loops and correct condition for
the loops print the spaces and stars accurately
(Outer loop i<n; Inner loop j<n-i : for spaces ) and
Inner loop(j<i+1: for stars)
After each loop run print an empty space so to
continue from the next line.
1 2 3 4 5 6
2 4 6 8 10 12
3 6 9 12 15 18
4 8 12 16 20 24
5 10 15 20 25 30
6 12 18 24 30 36
Coding:
Output:
PSEUDOCODE:
Initialize variable n(for no of rows).
Using two for loops and correct conditions
(Outer loop i<=n and j<=n for inner loop).
Print the pattern using (i*j).
After each loop run print an empty space so to
continue from the next line.
Aim: Write a program to check that the given number is prime, Armstrong or perfect using the concept of
functions.
Coding:
PSEUDOCODE:
Get number:Fundamentals
Prompt user to
of enter a number and store it.
C programing(23CS003)
Page | 29 Japit Singh
Check prime: Call a function to check if the number is prime
2310990612
and print appropriate message.
Check perfect: Call a function to check if the number is perfect
Program No. – 16
Page | 30 Fundamentals of C programing(23CS003) Japit Singh
2310990612
Aim: Write a program to calculate the area and circumference of a circle using functions.
Coding:
Output:
PSEUDOCODE:
Initialize variable radius(for the radius) as
double.
Call the functions area and circumference which
namely compute the area and circumference of the
circle.
Then print the result i.e. area and circumference.
Program No. – 17
Page | 31 Fundamentals of C programing(23CS003) Japit Singh
2310990612
Aim: Write a program to swap two variables using the concept of call by value and call by reference.
Coding:
Output:
Program No. – 18
Coding:
Coding:
PSEUDOCODE:
Get array size: Prompt user for the number of elements and
store it in a variable.
Input elements: Create an array of the given size and prompt
Page | 34 the user to enter each element, storing them
Fundamentals inprograming(23CS003)
of C the Japit Singh
corresponding array indices. 2310990612
Perform operations: Call functions for insert, update, delete
(based on user input for element and index), handling potential
PSEUDOCODE:
Get array size: Prompt user to enter the number of elements in the
array and store it in a variable.
Create array: Declare an integer array with size entered by the user.
Input elements: Loop through each element of the array, prompt the
user to enter a value, and store it in the corresponding array index.
Calculate sum: Call a function SumofArray that takes the array and
its length as input, iterates through the array, adds each element to a
running total (Sum), and returns the final sum.
Print sum: Print the calculated sum of all elements in the array.
Output:
Program No. – 20
Coding:
PSEUDOCODE:
Initialize number as int equal to 5.
Print the original number.
Call the function square by passing address of the
variable and use the concept of pointers.
Now in function from the address get the value of
the variable using *.
Compute the result and return the squared number.
Program No. – 21
Output:
Program No. – 22
Coding: