You are on page 1of 62

NAME: SIDDHARTH BHUSHAN

SUBJECT: Programming for


problem solving lab (PES-111)
CSE

ROLL NO(COLLEGE ID): 200261

BRANCH NAME: CSE

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

Print

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

Declare n1,n2,n3 and


max

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

Enter the person’s age

Is age >=18?

Display “you are not


YES
eligible to vote”

NO

Display “you are not eligible to


vote”

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 2. Input A,B,C

Step 3. If (A>B) and (A>C) then print “A is greater”.

Else if (B>A) and (B>C) then print “B is greater”.

Else print “C is greater”.

Step 4. Stop
Q6-WAP to find vowel using switch case.
6-
Start

Read ch from user

Declare variable ch

Assign vowels to diff cases

NO

YES

Print “Vowel” Stop


Algorithm: -

Step 1: Start

Step 2: Declare character type variable ch

Step 3: Read ch from User

Step 4: Checking both lower and upper case vowels and


assigning each of them to different case.
IF case matches
Print "Vowel"
Default:
Print "Consonant"
Step 5: Stop
Q7-WAP to find even and odd no using switch case.

7-
Start

Read number

Switch n%2==0

FALSE Write odd


number

TRUE

Write even number

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

Read values and pass parameters

Add number in function

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-

Declare A[r][c] B[r][c]


and C[r][c]

Read r,c,p,A[][] and B[]


[]

i=0,j=0

i<r j<c yes C[i][j]=A[i][j] + B[i][j]


yes

no
no

i=0,j=0 j=j+1
Print C

End
Algorithm:

Step 1: Start

Step 2: Declare matrix A[r][c];


and matrix B[r][c];
and matrix C[r][c]; r= no. of rows, c= no.
of columns

Step 3: Read r, c, A[][] and B[][]

Step 4: Declare variable i=0, j=0

Step 5: Repeat until i < r

5.1: Repeat until j < c

C[i][j]=A[i][j] + B[i][j]
Set j=j+1

5.2: Set i=i+1

Step 6: C is the required matrix after addition


Step 7: Stop
Q12-WAP ot find even and odd numbers using function.
12-

Start

Enter a Number

If Number%2==0

Yes No

Print Even Print Odd

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

Declare char Str[100] ,int


Length = 0

Read Str

while (Str[Length] != '\0')

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[].

Step 3 -The while loop iterates from the first character to


the last character of the array. i.e. the last character of
the array is null.

Step 4-Print the i value which is the length of the string.


Q14-WAP to calculate the mean of first ten numbers using an array.
14-

Start

Declare float a[100],


sum=0, avg; int i, n;

Read i,n,a[100]

for(i=0; i< n; i++)

True
False

sum = sum + a[i]

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

Declare structure struct student char


firstName[50], int roll,float marks, s[5]

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

Input n1, n2, n3, n4,


n5

Sum=n1 + n2 + n3 +
n4 + n5

Avg=Sum/5

Print Avg

Stop
Algorithm

Step 1- start

Step 2-input the sum.

Step 3- sum( n1+ n2+ n3).

Step 4- AVG sum/3.

Step 5- print avg.

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 2-input numbers

Step 3- check if(a==b)

Step 4- print 1 for true and 0 for false

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

Input from user a,b

Use sizeof(a)

Display size

End
Algorithm

Step 1- start

Step 2-declare variables with keywords

Step 3- Input value of variables

Step 4- use sizeof function

Step 5- print size of variables

Step 6- stop.
Q19-WAP to perform the logical operator.

19-
Start

ALGORITHM
Input n1, n2, n3

Step 1- Start True


If(n1>n2) If(n2>n3)
False Print second no. is
largest
Step 2- 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 2-input the numbers

Step 3- variable = Expression1 ? Expression2 : Expression3

Step 4- print or execute expression

Step 5- stop.
THE END

You might also like