MNNIT CC 2021-22 Classes

C Class 5

.. Previous Page

Class recording: Here

PPT: Part 1 and Part 2

February 06th, 2022

C language logo

[Scroll to the bottom of this page to discuss stuff].

Tasks

do…while loop

  1. Write a program (WAP) that asks the user to enter an integer. If the number is even, the program should display the square of the number and continue asking the user to enter another number. If the number is odd, the program should display the square root of the number and continue asking the user to enter another number. The program should stop when the user enters 0 or negative number.

break, continue, nested loops

  1. Write a program that asks user for a number in a loop and then:
    • if the number is even (except 2), continues to the next iteration
    • else if number is non-prime, print that the number is odd and non-prime.
    • else if the number is prime, print that the number is prime and exit the loop.
  2. WAP to display all palindromic numbers b/w 1 and 500.
  3. WAP to print the binary representation of all number b/w 1 and 500.

Write separate programs to print the following series:

  1. 1, 4, 7, 10, …, 100
  2. 1, 4, 9, 16, …, 100
  3. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …, 100 <- This is called the Fibonacci series.

Write separate programs using nested loops to print the following patterns:

  1. *
    **
    ***
    ****
    *****
    
  2. 1
    12
    123
    1234
    12345
    
  3.     $
       $$
      $$$
     $$$$
    $$$$$
    
  4.     #
       # #
      # # #
     # # # #
    # # # # #
    
  5. 123454321
     1234321
      12321
       121
        1
    
  6.     1
       212
      32123
     4321234
    543212345
    
  7. 1       1
    12     21
    123   321
    1234 4321
    123454321