Professional Documents
Culture Documents
YEAR: 2020-2021
Q1- WAP to calculate the mean of first n numbers using while,do-while loop
and for loop.
1-
Start
Enter n numbers
I<=n sum=sum+i
Avg= sum/n
Stop
Algorithm: -
Step 1 -Start
Step 2- Enter n
Step 3- Run loop to n and sum=sum+i
Step 4- Avg=sum/n
Step 5- Print avg
Step 6-Stop
Q2- WAP to swap two numbers without using third number.
2-
Start
Input A,B
A+A+B B=A-B
A=A-B
Print A,B
Stop
Algorithm: -
STEP 1: START
STEP 2: ENTER A, B
STEP 3: PRINT A, B
STEP 4: A = A + B
STEP 5: B= A - B
STEP 6: A =A - B
STEP 7: PRINT A, B
STEP 8: END
Q3-WAP to find largest no using ternary operator.
3-
Start
Read n1,n2,n3
Max=(n1>n2)?(n1>n3:n3):(n2>n3?n2:n3);
Print Max
Stop
Algorithm: -
Step 1 -Start
Step 2-Declare a variable a, b, c and largest as integer;
Step 3-Read the number a, b and c;
Step 3-max = a > b ? (a > c ? a : c) : (b > c ? b : c);
Step 4 -print max;
Step 5-Stop
Q4-Write a program to find the eligibility for vote using if and else.
4-
Start
Is age >=18?
NO
Stop
Algorithm: -
Step 1: Start
Step 2: Accept the age of the person.
Step 3: If age is greater than or equal to 18, then display 'You are
eligible to vote'.
Step 4: If age is less than 18, then display 'You are not eligible to
vote'.
Step 5: Stop
Q5-WAP to find largest no using if else and logical operator.
5- Start
Input A,B,C
If A>B
NO YES
If B>C If A>C
NO NO
Algorithm: -
Step 1. Start
Step 4. Stop
Q6-WAP to find vowel using switch case.
6-
Start
Declare variable ch
NO
YES
Step 1: Start
7-
Start
Read number
Switch n%2==0
TRUE
Stop
Algorithm: -
Step 1- Start
Step 2-Input number from user. Store it in some variable say num.
Step 3-Switch the even number checking expression i.e. switch(num %
2).
Step 4-The expression (num % 2) can have two possible values 0 and 1.
Hence write two cases case 0 and case 1.
Step 5-For case 0 i.e. the even case print "Even number".
Step 6-For case 1 i.e. the odd case print "Odd number"
Step 7- Stop
Q8-WAP to find sum of two numbers using function.
8-
Start
Declare variable
Print sum
Stop
Algorithm: -
Step 1: Start
Step 2: Declare variable number1, number2 and sum
Step 3: Read Variable number1, number2
Step 4: Perform operation (sum= number1+ number2)
Step 5: Print sum variable
Step 6: Call this function and print value
Step 7: Stop
Q9-WAP to find largest number given of three number using function
9-
Algorithm: -
Start
Step 1- Start
Step 2-Ask the user to enter three integer values.
Step 3-Read the three integer values in num1, num2, and
num3 (integer variables).
Declare variables
Step 4-Check if num1 is greater than num2.
Step 5-If true, then check if num1 is greater than num3.
Read as
If true, then print ‘num1’ values and pass
the greatest parameters to function
number.
If false, then print ‘num3’ as the greatest number.
Step 6-If false, then check if num2 is greater than num3.
If true, then print ‘num2’ as the greatest number.
Compare
If false, then print ‘num3’ as the greatestnumbers
number. using function
Print largest
Stop
Q10-WAP to find the factorial no using recursion function.
10-
Start
Read number
I=1 fact=1
Is i<=n
Algorithm: -
Step 1: Start
Step 2: Read number n
Step 3: Call factorial(n)
Step 4: Print factorial f
Step 5: Stop
factorial(n)
Step 1: If n==1 then return 1
Step 2: Else
f=n*factorial(n-1)
Step 3:
Return f
Q11-WAP to addition of 2D array.
Start
11-
i=0,j=0
no
no
i=0,j=0 j=j+1
Print C
End
Algorithm:
Step 1: Start
C[i][j]=A[i][j] + B[i][j]
Set j=j+1
Start
Enter a Number
If Number%2==0
Yes No
Stop
Algorithm:
READ number
remainder=number%2
IF remainder==0
WRITE "Even Number"
ELSE
WRITE "Odd Number"
ENDIF
Q13-WAP to find the length of string using while loop.
13-
Start
Read Str
True
False
Length++
Print length
End
ALGORITHM
Step 1 -The string is nothing but an array of characters.
Step 2-Read the entered string using gets() function and
store into the character array s[].
Start
Read i,n,a[100]
True
False
Print Sum
Print average
End
ALGORITHM
START
Step 1 → Take an integer set A of n values
Step 2 → Add all values of A together
Step 3 → Divide result of Step 2 by n
Step 4 → Result is mean of A's values
STOP
Q15-WAP to read and display student type structure takes student elements
such as names,branch,age,id no.
15-
Start
For(i=0;i<5;++i)
False
True
For(i=0;i<5;++i)
Read firstName,roll,marks
True False
Print firstName,roll,marks
End
ALGORITHM
Step 1- Start
Step 2- Declare structure struct student char
firstName[50], int roll,float marks, s[5]
Step 3- Read firstName,roll,marks
Step 4- Print firstName,roll,marks
Step 5- Stop
Q16-WAP to find the mean of given of 5 numbers.
16-
Start
Sum=n1 + n2 + n3 +
n4 + n5
Avg=Sum/5
Print Avg
Stop
Algorithm
Step 1- start
Step 6- stop.
Q17-WAP to perform equality operator.
17-
Start
Input a,b
If(a==b)
True
False
Print result
Stop
Algorithm
Step 1- start
Step 5- stop.
Q18-WAP to find the size of basic data types use in C.
18-
Start
Initialize variables
like int a, float b
Use sizeof(a)
Display size
End
Algorithm
Step 1- start
Step 6- stop.
Q19-WAP to perform the logical operator.
19-
Start
ALGORITHM
Input n1, n2, n3
True False
Step 3- If(n1>n2) Print first no. is largest
Print first no. is Stop
largest
Step 4- If(n2>n3) Print second no. is largest
Step 5- END
Q20-WAP to perform ternary operator.
20-
Start
Declare n1,n2
Input n1, n2
Expression 1
False True
Expression 3 Expression 2
Print expression
Stop
Algorithm
Step 1- start
Step 5- stop.
THE END