C++ Important Programs | Programming Practice with C++

1. Write a C++ program to check two numbers are equal or not.

    Solution:

    Output – 1:

    Enter 2 numbers: 12 12

    Numbers are equal

    Output – 2:

    Enter 2 numbers: 23 45

    Numbers are not equal

    2. Write a program to find the greater number among two numbers.

    Solution:

    OR

    Output:

    Enter 2 numbers: 23 56

    Greater number is: 56

    3. Write a program to check whether a number is even or odd.

    Solution:

    Output – 1:

    Enter a number: 4

    4 is even number

    Output – 2:

    Enter a number: 7

    7 is odd number

    4. Write a program to check whether a year is leap year or not.

    Solution:

    Output – 1:

    Enter a year: 2020

    2020 is leap year

    Output – 1:

    Enter a year: 2025

    2025 is not leap year

    5. Write a C++ program to find the largest number among three numbers.

    Solution:

    Output:

    Enter 3 numbers: 10 20 30

    Largest number is: 30

    6. Write a C++ program to check whether a character is vowel or not using switch case.

    Solution:

    Output – 1:

    Enter any character: A

    A is a vowel

    Output – 2:

    Enter any character: r

    r is not a vowel

    7. Write a C++ program to print 1st 100 natural numbers.

                                 OR

    Write a program in C++ to print the number from 1 to 100.

    Solution:

    Output:

    First 100 Natural Number:

    1       2       3       4       5       6       7       8       9       10      11      12      13      14      15     16       17      18      19      20      21      22      23      24      25      26      27      28      29      30     31       32      33      34      35      36      37      38      39      40      41      42      43      44      45     46       47      48      49      50      51      52      53      54      55      56      57      58      59      60     61       62      63      64      65      66      67      68      69      70      71      72      73      74      75     76       77      78      79      80      81      82      83      84      85      86      87      88      89      90     91       92      93      94      95      96      97      98      99      100

    8. Write a C++ program to generate Multiplication Table.

    OR

    Write a C++ program to find the multiplication table of a number using for loop.

    Solution:

    Output:

    Enter a number: 5

    Multiplication Table of 5

    5 x 1 = 5

    5 x 2 = 10

    5 x 3 = 15

    5 x 4 = 20

    5 x 5 = 25

    5 x 6 = 30

    5 x 7 = 35

    5 x 8 = 40

    5 x 9 = 45

    5 x 10 = 50

    9. Write a C++ program to print multiplication table from 1 to 5.

    Solution:

    Output:

    Multiplication Table from 1 to 5

    1 x 1 = 1

    1 x 2 = 2

    1 x 3 = 3

    1 x 4 = 4

    1 x 5 = 5

    1 x 6 = 6

    1 x 7 = 7

    1 x 8 = 8

    1 x 9 = 9

    1 x 10 = 10

    ————-

    2 x 1 = 2

    2 x 2 = 4

    2 x 3 = 6

    2 x 4 = 8

    2 x 5 = 10

    2 x 6 = 12

    2 x 7 = 14

    2 x 8 = 16

    2 x 9 = 18

    2 x 10 = 20

    ————-

    3 x 1 = 3

    3 x 2 = 6

    3 x 3 = 9

    3 x 4 = 12

    3 x 5 = 15

    ————–

    ————-

    10. Write a program to calculate sum of first n natural numbers.

    Solution:

      Output:

      Enter a number: 6

      Sum of first 6 natural number:21

      Leave a Comment