0% found this document useful (0 votes)
44 views4 pages

Home Task 2

Uploaded by

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

Home Task 2

Uploaded by

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

Home Task 2

Question 1:
Write a program which takes a number as an input, then you have to calculate the sum
of all numbers.
Sample Input:
Enter the number: 5
Sample Output:
Sum of Numbers: 15 (Hint: 1+2+3+4+5)

Question 2:
Write a program which takes two values number and limit as input and then you have to display the table of
given number up to the given limit.
Sample Input:
Enter the number: 5
Enter the limit: 3
Sample Output:
Table of 5 up to 3 is
5*1=5
5 * 2 = 10
5 * 3 = 15

Question 3:
Write a program which takes number as input and then you have to display the factors of given number. You
have to calculate the sum of all factors.
Sample Input:
Enter the number: 10
Sample Output:
Factor of 10:
Sum of Factor:

1
18

10

Question 4:
Write a program which takes two numbers as input and then you have to find greatest common divisor (GCD)
of the given numbers.
Sample Input:
Enter the number1: 10

Enter the number1: 15


Sample Output:
GCD is: 5

Question 5:
Write a program which takes number as input and then you have to find the factorial of the given numbers.
Sample Input:
Enter the number: 5
Sample Output:
Factorial is: 120 (Hint: 1*2*3*4*5)

Question 6:
Write a program which takes number as input and then you have to find the given number is prime or not.
(Hint: Number is said to prime if it has exactly two factors otherwise it is not a primary number).
Sample Input:
Enter the number: 9

Sample Input:
Enter the number: 5

Sample Input:
Enter the number: 1

Sample Output:
Not a prime

Sample Output:
prime

Sample Output:
Not a prime

Question 7:
Write a program which generates the Fibonacci Series up to nth sequence number where n must be greater
than or equal to 3. In Fibonacci series, first and second number is entered by users then the next number is
generate by adding the previous two numbers you have generate this series up to nth sequence number .i.e.
Generate the Series up to 5 sequence number where first and second numbers of series are 2 and 3
respectively. The series will be. 2 3 5 8 13. You can see by adding previous two numbers the next number is
generated.
Sample Input:
Enter the first number of series: 5

Enter the first number of series: 7


Series iteration: 6
Sample Output:
Fibonacci series is: 5 7 12 19 31 50

Question 8:
Write a program which generates the following series up to nth sequence number where n must be greater
than or equal to 3. In series, first and second number is entered by users then the next number is generate by
adding the previous two numbers next time number is generate by multiplying previous two numbers and
series will generate with the same passion .You have to generate this series up to nth sequence number .i.e.
Generate the Series up to 5 sequence number where first and second numbers of series are 2 and 3
respectively. The series will be. 2, 3, 5(+), 15(*), 20(+). You can see by adding previous two numbers the next
number is generated.

Sample Input:
Enter the first number of series: 5
Enter the first number of series: 7
Series iteration: 5
Sample Output:
Fibonacci series is: 5, 7, 12, 84, 96, 8064

Question 9:
You have to develop a game guess a number. In the game a number is generated randomly and you
does not know about that number but the range of the randomly generated number is between 0 - 50.
You have to guess a number if guessed number matched with randomly generated then you won the
match. If you guessed number is greater than the random number it ask user your guessed number is
greater next time user guess the lesser number or if guessed number is lesser than the random
number then it ask user your guessed number is lesser next time user guess higher number. This
process of guessing a number continues unless user guessed the random number. The random
number is generated using function rand () which is defined in library stdlib.h. Elaborate how to use
rand () function.

Note: If you any query regarding the Home Task discuss with me or with your TA. In case of
cheating both persons will award with zero. There will be the viva of Home Task so dont think
about cheating.

Best of Luck

You might also like