Class recording: Here
February 12th, 2022
[Scroll to the bottom of this page to discuss stuff].
- Write a program (WAP) to accept two numbers in input and display all numbers from the first number to the second number using a function that accepts the two numbers as arguments.
- WAP to accept a number from the user and display all prime numbers between 1 and that number using a for loop and function that accepts a number as an argument and returns alphabet ‘P’ if it is a prime number and ‘N’ if it is not a prime number.
- WAP to accept a number from the user and display the multiplication tables of all numbers from 1 to that number using a function that accepts a number as an argument and prints the multiplication table of that number.
- WAP to input two numbers from the user and calculate nCr using a function that accepts an integer as an argument and returns the factorial of that number.
- Write the 3rd program above by creating a header file
utility.h
containing the required table printing function.
-
Find the output of the following code:
#include <stdio.h> int main() { int x = 1, y = 2, z = 3; printf(" x = %d, y = %d, z = %d \n", x, y, z); { int x = 10; float y = 20; printf(" x = %d, y = %f, z = %d \n", x, y, z); { int z = 100; printf(" x = %d, y = %f, z = %d \n", x, y, z); } } return 0; }
Options:
-
Output:
x = 1, y = 2, z = 3 x = 10, y = 20.000000, z = 3 x = 1, y = 2, z = 100
-
Output:
x = 1, y = 2, z = 3 x = 10, y = 20.000000, z = 3 x = 10, y = 20.000000, z = 100
-
Compilation Error
-
Output:
x = 1, y = 2, z = 3 x = 1, y = 2, z = 3 x = 1, y = 2, z = 3
Click here for answer
Answer: (2). For explanation, read this article. -
-
Attempt this worksheet on variable scoping. You should read about
extern
keyword (see below) before attempting this.
- Read about
extern
keyword. You can use this. - Read about recursion in C, which will help in easy understanding of the next class. You can use this.
{% include disqus.html %}