Home

Learn Programming & Prepare for NPTEL Exams... Swayam Solver is your one-stop destination for NPTEL exam preparation.

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

 

Introduction to Programming in C - July 2026

 Please scroll down for latest Programs   ðŸ‘‡

Code compiled and tested successfully!



Week 3: Assignment 3: Question 1

Due date on 2026-08-14, 23:59 IST

Q.

Complete the function `int find_factorial(int k)` to find the factorial of the positive number `k`.


The factorial of a positive integer `k`, denoted by `k!`, is the product of all positive integers less than or equal to `k`.


k! = k × (k − 1) × ... × 1


Input

The first line of input is a positive integer `N`.

The next line contains `N` positive integers.

Output

For each `k` given as input, print `k!`.

Note: The code stub given takes care of reading the input, passing it to the function `find_factorial` and printing the value returned by the function.
You only need to complete the function `find_factorial`, which takes a single positive integer as input and returns its factorial.

Note: You can assume that each input is less than 10.

Sample input

3

4

3

5

Sample Output

24  6  120


Explanation

The first input (3) denotes there are three input's for k.
4! = 1 * 2 * 3 * 4 = 24
3! = 1 * 2 * 3  = 6
4! = 1 * 2 * 3 * 4  *5 = 120


Complete Program

C
#include <stdio.h>

int find_factorial(int k) {
    // --- START OF SOLUTION CODE ---
    int fact = 1;
    for (int i = 1; i <= k; i++) {
        fact *= i;
    }
    return fact;
    // --- END OF SOLUTION CODE ---
}

int main() {
    int n, k;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &k);
        printf("%d", find_factorial(k));
        if (i < n - 1) printf(" ");
    }
    
    return 0;
}

Code Snippet to Paste in the Editor

C
    // --- START OF SOLUTION CODE ---
    int fact = 1;
    for (int i = 1; i <= k; i++) {
        fact *= i;
    }
    return fact;
    // --- END OF SOLUTION CODE ---


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.

Evaluation Results

CompilationSuccessful|Public Test Cases: 2/2 Passed

Note: These tests may not be considered while scoring.

Public Test Cases

Test Case
Input
Expected Output
Output
Status
Test Case 1

3 4 3 5

24 6 120
24 6 120
-
Test Case 2

1 8

40320
40320
-




Week 3: Assignment 3: Question 2

Due date on 2026-08-14, 23:59 IST

Q.

Complete the function `int parking_fee(int hours)` to compute the parking fee based on the following rules:


- The first 2 hours are charged at ₹20 per hour.

- Every additional hour is charged at ₹30 per hour.

- If `hours` is 0, the parking fee is ₹0.


Input


A single integer `hours`, representing the number of hours a vehicle was parked.


Output


Print the parking fee, calculated according to the formula.

Sample Input

5

Sample Output

130

Explanation

The vehicle is parked for 5 hours:
First 2 hours: 2 × ₹20 = ₹40
Remaining 3 hours: 3 × ₹30 = ₹90
Total parking fee = ₹40 + ₹90 = ₹130.

Sample Input

2

Sample Output

40

Explanation

First 2 hours: 2 × ₹20 = ₹40

Complete Program

C
#include <stdio.h>

int parking_fee(int hours)
{
    // --- START OF SOLUTION CODE ---
    if (hours <= 2) {
        return hours * 20;
    } else {
        return 40 + (hours - 2) * 30;
    }
    // --- END OF SOLUTION CODE ---
}

int main()
{
    int hours;
    scanf("%d", &hours);
    printf("%d", parking_fee(hours));
    return 0;
}

Code Snippet to Paste in the Editor

C
    // --- START OF SOLUTION CODE ---
    if (hours <= 2) {
        return hours * 20;
    } else {
        return 40 + (hours - 2) * 30;
    }
    // --- END OF SOLUTION CODE ---



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.

Evaluation Results

CompilationSuccessful|Public Test Cases: 2/2 Passed

Note: These tests may not be considered while scoring.

Public Test Cases

Test Case
Input
Expected Output
Output
Status
Test Case 1

5

130
130
-
Test Case 2

2

40
40
-



Week 3: Assignment 3: Question 3

Due date on 2026-08-14, 23:59 IST

Q.

Caesar Cipher 


Write a C program that takes a single lowercase English letter and a positive integer k as input, and shifts the letter k positions forward in the alphabet using the Caesar cipher technique.


If the shift goes beyond 'z', it should wrap around to the beginning of the alphabet.


You may assume the input is always a valid lowercase letter ('a' to 'z') and 0 ≤ k ≤ 25. 


Input


The first line contains a single lowercase letter.


The second line contains an integer k.


Output


Print the lowercase letter obtained after shifting the input letter forward by k positions.


Sample Input


x

5


Sample Output


c


Explanation


Starting from x, shifting forward by 5 positions gives:


x → y → z → a → b → c


Hence, the output is c.

Sample Input


d

7


Sample Output


k

Explanation

Starting from d, shifting forward by 7 positions gives:


d → e → f → g → h → i → j → k


Hence, the output is k.

 

Complete Program

C
// --- START OF SOLUTION CODE ---
#include <stdio.h>

int main() {
    char ch;
    int k;
    scanf(" %c", &ch);
    scanf("%d", &k);
    printf("%c", (ch - 'a' + k) % 26 + 'a');
    return 0;
}
// --- END OF SOLUTION CODE ---

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
#include <stdio.h>

int main() {
    char ch;
    int k;
    scanf(" %c", &ch);
    scanf("%d", &k);
    printf("%c", (ch - 'a' + k) % 26 + 'a');
    return 0;
}
// --- END OF SOLUTION CODE ---


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.

Evaluation Results

CompilationSuccessful|Public Test Cases: 2/2 Passed

Note: These tests may not be considered while scoring.

Public Test Cases

Test Case
Input
Expected Output
Output
Status
Test Case 1

x 5

c
c
-
Test Case 2

d 7

k
k
-















































































































No comments:

Post a Comment

Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.