0% found this document useful (0 votes)
30 views5 pages

Exercise 1.1

Notu

Uploaded by

gprakash1626
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views5 pages

Exercise 1.1

Notu

Uploaded by

gprakash1626
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

PSG COLLEGE OF TECHNOLOGY, COIMBATORE-641004

EXERCISE SHEET -2

Write an algorithm and draw a flowchart for the following problems statements. Execute your
flowchart in the flowgarithm and record your output.

1. Find the sum and average of three numbers.


Description: sum=number1+number2+number3
Average=sum/3

2. Find odd or even number using conditional operator

Description:
if number%2 = 0 then even number otherwise odd number

3. Find whether the given year is leap year or not.

If( year % 4 = 0 and year % 100! = 0) or year %400=0 then it is leap year

Let us consider the year 2007:


year = 2007
year / 4 = 2007 / 4 = 501
2007 % 4 = 3
2007 % 400 = 7
Therefore, 2007 is not a leap year.

4. Generate the first n terms of the Fibonacci Sequence

Description: Initial Fibonacci numbers are 0 and 1. Next number can be generated by
adding two numbers.
So 0+1=1. Therefore next number can be generated by adding two previous.
so Fibonacci series is 0 1 1 2 3 5 ……

5. Generate all prime numbers between 1 and n. Where n is the value supplied by
the user.

Description:
Prime number is a number which is exactly divisible by one and itself only Ex: 2,
3,5,7,………;

6. count the number of digits in a given integer using loop

Description: Read number a; While (a!=0), a=a/10, n=n+1


Input: Enter a number : 1234
Number of digits : 4
7. Check whether the given number is positive, negative or zero

Description:
Compare the given number with greater than or less than zero
Input: -10
Output : Negative

8. Find the reverse of a given integer

Description:
Use the concept of ones tens hundreds and thousands places place value system. Like
if 1234 a number is given then, find the number by taking the remainder and
multiplying the number by 10 to shift its place by one unit like remainder is 1 then
10+2 , 120+3 , 1230+4 we get that number.

Enter the number to find its reverse: 12345


Output: 54321

9. Write an algorithm and draw a flowchart to find the summation of the following
series: 1+3+5+7+…..N , where N is an odd positive integer.

Description:

Input N = 7
Output: 16

10. Find the roots of a quadratic equation.

Description:

Roots of quadratic equation are −b±√b2−4ac /2a

INPUT:
ENTER VALUES FOR a,b,c 1 4 4
OUTPUT:
THE ROOTS ARE EQUAL AND THEY ARE.. Root1=-2 Root2=-2
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

PSG COLLEGE OF TECHNOLOGY, COIMBATORE-641004

EXERCISE SHEET -3

Write an algorithm and draw a flowchart for the following problems statements. Execute your
flowchart in the flowgarithm and record your output.

1. Find the factorial of a given integer using non-recursive function.

Description: n!=n*(n-1)*(n-2)…..*1

INPUT:
ENTER A VALUE FOR n 5
OUTPUT:
THE FACTORIAL OF A GIVEN NUMBER IS..120

2. Find the factorial of a given integer using recursive function.

Description:The function which calls itself is called recursive function

3. Find the GCD of two given integers by using the recursive function

Description: The greatest common divisor (gcd) of two or more integers, when at least
one of them is not zero, is the largest positive integer that divides the numbers without a
remainder.
For example, the GCD of 8 and 12 is 4.

4. The GCD of two given integers using non-recursive function.

Description:
GCD means Greatest Common Divisor. i.e the highest number which divides the given
number Ex: GCD(12,24) is 12
Formula: GCD= product of numbers/ LCM of numbers

INPUT:
enter the two numbers whose gcd is to be found:5,25
OUTPUT:
GCD of a,b is : 5

5. Find whether the given matrix is symmetric or not.

Description: A square matrix is said to be symmetric matrix if the transpose of the


matrix is same as the given matrix. Symmetric matrix can be obtained by changing
row to column and column to row.
INPUT:
Enter row-order and col-order of matrix: 2
2
Enter 4 values one by one 12
34
34
54

OUTPUT:
Matrix is symmetric

6. Perform addition of two matrices.

Description: Consider two matrices and their order is R1xC1 and R2XC2. The
condition is R1==R2 and C1==C2,then only the addition is possible.

INPUT:
ENTER ORDER OF A MATRIX 2
2
ENTER ORDER OF B MATRIX 2
2
ENTER A MATRIX 1
2
3
4
ENTER B MATRIX 1
2
3
4
OUTPUT:
After addition of two matrices :
24
68

7. Perform multiplication of two matrices.

Description: Consider two matrices and their order is R1xC1 and R2XC2. The
condition is C1==R2 ,then only the multiplication is possible.

INPUT:
Enter the size of A Mtrix (Row and Col): 2 2
Enter the size of B Mtrix (Row and Col): 2 2
Enter Matrix Value Row by Row
10
26
Enter Matrix Value Row by Row
34
42
OUTPUT:
A matrix is:
10
26
B Matrix is:
34
42
C matrix is:
34
24 20
8. Program to print name of days in a week using switch case

Description : Day 1 : Sunday……… Day 7: Saturday

9. Program to find square of a given number using function

Description: a=12
Square = 12*12 =144

10. Check whether a number is strong number or not.

Description: Strong numbers are the numbers whose sum of factorial of digits is equal to
the original number. Example: 145 is a strong number.Ex:1!+4!+5!=1+24+120=145

INPUT:
Enter a number:145
OUTPUT:
145 is a strong number

You might also like