TP-05 DSP Loop Part-II
TP-05 DSP Loop Part-II
TP-05
Loop (Part-II)
in C/C++
Problem2: Write a program to sum all numbers from n to 1000 except the number
100, where n is an integer number input by the user.
Examples:
INPUT:
Enter a number: 5
Output:
The summation from 5 to 1000 except the number 100 is: 500390
…………………………………………………………
INPUT:
Enter a number: 250
Output:
The summation from 250 to 1000 except the number 100 is: 469375
Problem3: Write a program to display all even numbers between 1 and 50 using a
for loop.
Examples:
Output:
The summation of all even numbers between 1 and 50: 2 + 4 + 6 + … 48
= 600
Problem4: Create a program that calculates and prints the power of 2 for the first 10
natural numbers using a for loop.
Examples:
Output:
The power of 2 for the first 10 natural numbers are:
21 = 2
22 = 4
23 = 8
24 = 16
25 = 32
26 = 64
27 = 128
28 = 256
29 = 512
210 = 1024
Problem5: Create a program to ask a user to input a number. The program will tell
the user whether it is a prime number or not.
INPUT:
Enter a number: 5
Output:
5 is a prime number because it is only divisible by itself and 1.
…………………………………………………………
INPUT:
Enter a number: 12
Output:
12 is not a prime number because it is not only divisible by itself and 1.
Problem6: Create a program to identify and print all prime numbers between n and
m using a for loop, where n and m are integer numbers input by the user.
INPUT:
Enter n: 20
Enter m: 50
Output:
All prime numbers between 20 and 50 are: 23,29,31,37,41,43 and 47.
…………………………………………………………
INPUT:
Enter n: 2
Enter m: 100
Output:
All prime numbers between 2 and 100 are: 2, 3, 5, 7, 11, 13, 17, 19,
23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, and 97.