NPTEL » Introduction to Programming in C
Please scroll down for latest Programs. 👇
Week 1: Assignment 1 - Question 1
Due on 2025-08-07, 23:59 IST
Given three distinct integers a b and c, write a C program to find the second
largest number among them.
Input
Three distinct integers a b c.
The first input is the integer a.
The second input is the integer b.
The third input is is the integer c.
The first input is the integer a.
The second input is the integer b.
The third input is is the integer c.
Output
The second largest among a, b and c
Note: The assignment evaluation is automated.
Therefore, do not print (using printf) anything other than the output value.
Note: The assignment evaluation is automated.
Therefore, do not print (using printf) anything other than the output value.
Statements such as printf("Enter the first integer") printf("The second largest integer is %d", val) etc will lead to incorrect output.
Ideally, the only printf line in the code should be printf("%d",val); Here val can be any variable that stores the output value.
Sample input
------------------
2 3 1
Sample output
-------------------
2
Explanation
----------------
2 is the second largest among {2, 3 , 1}.
1 < 2 and 2 < 3.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2 3 1 | 2 | 2 | Passed |
Test Case 2 | 13 34 27 | 27 | 27 | Passed |
Week 1: Assignment 1 - Question 2
Due on 2025-08-07, 23:59 IST
Write a C program to convert a length given in centimeters into feet and inches.
Use the following conversions: 1 inch = 2.54 cm, 1 foot = 12 inches, 1 foot = 30.48cm.
Use the following conversions: 1 inch = 2.54 cm, 1 foot = 12 inches, 1 foot = 30.48cm.
Input
A non-negative integer, the value of the length in cm.
Output
Output the length in feet followed by a space followed by the remaining length in inches (truncated to 2 decimal places).
Note: The code for input and output handling as well as the variables are given to you. Do not change these parts.
Note: The code for input and output handling as well as the variables are given to you. Do not change these parts.
Sample Input
170
Sample Output
5 6.93
Explantion
170 / 30.48 = 5.577 (approx)
So 170 cm is 5 feet and some inches
Remaining length in cm = 170 - (30.48 * 5) = 17.6cm
Remaining length in inches = 17.6 / 2.54 = 6.929 (approx)
The length in inches truncated to two positions is 6.96.
Explantion
170 / 30.48 = 5.577 (approx)
So 170 cm is 5 feet and some inches
Remaining length in cm = 170 - (30.48 * 5) = 17.6cm
Remaining length in inches = 17.6 / 2.54 = 6.929 (approx)
The length in inches truncated to two positions is 6.96.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 170 | 5 6.93 | 5 6.93 | Passed |
Test Case 2 | 100 | 3 3.37 | 3 3.37 | Passed |
Week 1: Assignment 1 - Question 3
Due on 2025-08-07, 23:59 IST
Write a C program to compute the area of a rectangle.
Use the formula:
Input
Two non-negative integers, the values of the length and breadth of the rectangle.
Output
Output the area of the rectangle as a single integer.
Sample Input
5 7
Sample Output
35
Explanation
The area of a rectangle is calculated as:
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 7 | 35 | 35 | Passed |