Home

Swayam Solver

Learn Programming & Prepare for NPTEL Exams...

Find your course

Explore Courses

Latest Blog Posts

NPTEL Introduction to programming in C Programming Assignments July-2025 Swayam

 

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.

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.


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.
Your last recorded submission was on 2025-07-27, 11:06 IST
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main() {
3
    int a, b, c;
4
    scanf("%d %d %d", &a, &b, &c);
5
    int secondLargest;
6
    if ((b < a && a < c) || (c < a && a < b))
7
        secondLargest = a;  
8
    else if ((a < b && b < c) || (c < b && b < a))
9
        secondLargest = b;
10
    else
11
        secondLargest = c;
12
    printf("%d",secondLargest);
13
    return 0;
14
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
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.

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.


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. 
Your last recorded submission was on 2025-07-27, 11:08 IST
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main() {
3
    int cm;
4
    int feet;
5
    float inches;
6
    scanf("%d", &cm);
7
    feet = cm/30.48;
8
    inches = (cm - feet*30.48)/2.54;
9
    printf("%d %.2f", feet, inches);
10
    return 0;
11
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
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: 

57=35

Your last recorded submission was on 2025-07-27, 11:11 IST
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main() {
3
    int l,b;
4
    int area;
5
    scanf("%d %d", &l,&b);
6
    area = l * b;
7
    printf("%d",area);
8
    return 0;
9
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
5 7
35
35
Passed