MNNIT CC 2021-22 Classes

C Class 7

.. Previous Page

Class recording: Here

PPTs:

February 13th, 2022

C language logo

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

Reading

  1. Read the attached presentation to learn about number system base conversions and working of bitwise operators before coming in for the next class.

Tasks

Offline practice

Recursion

  1. Write a program (WAP) to input a number n from the user and print the first n terms of the Fibonacci series using recursive function.
  2. WAP to input a number n and find the sum of first n natural numbers using a recursive function.
  3. WAP to input a number n and find the sum of first n even numbers using a recursive function.
  4. WAP to input a number n and find the sum of the digits of the number n using a recursive function.
  5. WAP to input a number n and a number p and find the value of n raised to the power p using a recursive function.
  6. WAP to take appropriate values (a and d) as input and find the sum of an Arithmetic Progression (AP) using recursion.
  7. Given a function defined as:

     f(1) = 3
     f(n) = 2 * f(n - 1) - 1
    

    WAP to input an integer n and display the sum of first n terms of the above series using recursion.


static keyword

Give the output of the following code:

#include <stdio.h>

void print_count()
{
    static int count1 = 1;
    int count2 = 1;
    printf( "Count1 = %d, Count2 = %d\n", count1++, count2++);
}

int main()
{
    print_count();
    print_count();
    print_count();
    return 0;
}
Click to reveal answer... Output: Count1 = 1, Count2 = 1
Count1 = 2, Count2 = 1
Count1 = 3, Count2 = 1

Online Judge

  1. Create CodeForces account if you haven’t done so already and solve the following problems:
  2. Create HackerRank account if you haven’t done so already and solve the following problems:

Meme zone

   
Meme1 Meme2
Meme3 Meme4
Meme5