Simple programs with their code

Spread the love

  1. WAP to print the table of any asked number.

Explanation:

We defined an integer variable, n, to prompt the user for the multiplication table they wish to display. To generate this table, we utilized a looping algorithm that produces results up to the specified range.

2. WAP to print the odd and even numbers

3. WAP to print whether the given number is prime or composite.

Explanation:

A number is considered prime if it is divisible only by 1 and itself. Therefore, we start checking from an index of 2 up to n-1 to identify composite numbers. If the number is divisible by any value within this loop, it indicates that the number is composite; thus, we set the flag to false, meaning the number is prime at the beginning. If while entering the loop, if divisible then flag is changed to true which means the num is composite. so at last bool function is checked whether it is true or false.

4. WAP to print the factors of a given number

5. WAP to print the factorials of a given number.

6. WAP to count the digit of a given number

If you don’t understand any logic of the program then just leave a comment.


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top