Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

Name – Shushant Sonwani

Registration no. – 2023CA95


WEEK 4 ASSIGNMENT SOLUTION

1. Write a program to print the following patterns.


*
**
***
****
*****
AB
ABC
ABCD
ABCDE
1
22
333
4444
55555
0
12
345
6789

1
12
123
1234
12345
*****
****
***
**
*
*
***
*****
*******
*********
*********
* * * * ** *
*****
***
*
1
121
12321
1234321
123454321

ABCDEF
ABCDE
ABCD
ABC
AB
A
1
123
12345
123
1
*******
*** ***
** **
* *
*****
****
***
****
*****

*
***
*****
***
*

*****
* *
* *
* *
*****
$****
*$ *
* $ *
* $*
****$

$***$
*$ $*
* $ *
*$ $*
$***$
1
11
121
1331
14641
1 5 10 10 5 1
******
*
*
*
*
******
2. Pascal Triangle is something where each element (i, j) is the sum of (i-1,j) and
(i-1,j-1)
element . Now create the Pascal triangle up to nth row with the help of FOR
LOOP. Value of
n will be key board input.
4. Write a program to print all the prime number between 1 to n using for loop,
break and
continue. The value of n will be input from key board. N>=300. Also count the
sum of all those
prime numbers and print the sum as well as numbers.
5. Write a program to print all the subset of 1, 2, 3 using for loop. Super set of a
set containing n
element has 2^n element. Mean if n=3, superset contain 8 element. Those are
null, 1, 2, 3, 1 2,
1 3, 2 3, 1 2 3. Print all the subset for a given value of n. N will be key board
input.
6. Print all the Romanian number from 1 to n. N will be key board input. N>=10.
Romanian letters are I, II, III, IV, V, VI, VII, VIII, IX, X, XI, XII, XII, XIV and XV and so
on.
7. Write a program to calculate the factorial of a number. Then calculate the
sum of n terms of the
following series: 1/1! + 2/2! + 3/3! + ……. + n/n! . N will be key board input.
N>=10. Factorial of
n= n*(n-1)*(n-2)*(n-3)*……….*1

8. Write a program to print all the ASCII values and their equivalent characters
using while loop.
The ASCII values vary from 0 to 255. Then also fill the entire screen with the
smiling face. The
ASCII value of smiling face 1.
9. Write a program to print all the Armstrong numbers between 1 and 500. If
the sum of cubes of
each number is equal to the number itself, then the number is called an
Armstrong number. For
example 153= 1^3 + 5^3+ 3^3.
10. Write a program to find the OCTAL, Hexadecimal and Binary forms of given
decimal
number. For example Octal, Hexadecimal, Binary of Decimal number 10 are A,
12, 1010.
Decimal number should key board input.
11. The natural logarithm can be approximated by the following series.
(X-1)/x + 1/2(x-1/x)2 + ½(x-1/x)3 +……… + ½(x-1/x)n If x, n is input through key
board, write a
program to calculate sum of first n terms of this series.

You might also like