Exercise 1.1
Exercise 1.1
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.
Description:
if number%2 = 0 then even number otherwise odd number
If( year % 4 = 0 and year % 100! = 0) or year %400=0 then it is leap year
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,………;
Description:
Compare the given number with greater than or less than zero
Input: -10
Output : Negative
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.
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
Description:
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
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.
Description: n!=n*(n-1)*(n-2)…..*1
INPUT:
ENTER A VALUE FOR n 5
OUTPUT:
THE FACTORIAL OF A GIVEN NUMBER IS..120
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.
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
OUTPUT:
Matrix is symmetric
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
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: a=12
Square = 12*12 =144
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