Home

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

NPTEL Problem Solving Through Programming In C - Programming Assignment | July-2026

NPTEL Problem Solving Through Programming In C - Programming Assignment | July-2026



  Please scroll down for latest Programs   ðŸ‘‡ 


Code compiled and tested successfully!



Problem Solving through Programming in C

NPTEL


Week-03: Practice Program-01

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

Your last recorded submission was on 2026-08-10, 17:10 IST.

Q.

Write a C Program to calculates the area (floating point number with two decimal places) of a Circle given it’s radius (integer value). The value of Pi is 3.14.

[Marks for Week 3 Programming assignments will not be evaluated finally. This is for users to get familiar with programming in google course builder platform]


Complete Program

C
#include <stdio.h>
#define PI 3.14

void main() {
    int radius;
    float area;

    scanf("%d", &radius);

    // --- START OF SOLUTION CODE ---
    area = PI * radius * radius;
    // --- END OF SOLUTION CODE ---

    printf("Area of a circle = %5.2f", area);
}

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    area = PI * radius * radius;
// --- 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

7

Area of a circle = 153.86
Area of a circle = 153.86
-
Test Case 2

50

Area of a circle = 7850.00
Area of a circle = 7850.00
-


Week-03: Practice Program-02

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

Your last recorded submission was on 2026-08-12, 14:46 IST.

Q.

Write a C program to check if a given Number is zero or Positive or Negative Using if...else statement.

[Week 3 programming assignments will not be considered for final evaluation]


Complete Program

C
#include <stdio.h>

int main() {
    double number;
    scanf("%lf", &number);

    // --- START OF SOLUTION CODE ---
    if (number == 0) {
        printf("The number is 0.");
    } else if (number < 0) {
        printf("Negative number.");
    } else {
        printf("Positive number.");
    }
    // --- END OF SOLUTION CODE ---

    return 0;
}

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    if (number == 0) {
        printf("The number is 0.");
    } else if (number < 0) {
        printf("Negative number.");
    } else {
        printf("Positive number.");
    }
// --- 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: 3/3 Passed

Note: These tests may not be considered while scoring.

Public Test Cases

Test Case
Input
Expected Output
Output
Status
Test Case 1

14.05

Positive number.
Positive number.
-
Test Case 2

0.45

Positive number.
Positive number.
-
Test Case 3

-50

Negative number.
Negative number.
-



Week-03: Practice Program-03

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

Your last recorded submission was on 2026-08-10, 18:53 IST.

Q.

Write a C program to check whether a given number (integer) is Even or Odd.

[Week 3 programming assignments will not be considered for final evaluation]

Complete Program

C
#include <stdio.h>

int main() {
    int number;
    scanf("%d", &number);

    // --- START OF SOLUTION CODE ---
    if (number % 2 == 0) {
        printf("%d is even.", number);
    } else {
        printf("%d is odd.", number);
    }

    return 0;
    // --- END OF SOLUTION CODE ---
}

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    if (number % 2 == 0) {
        printf("%d is even.", number);
    } else {
        printf("%d is odd.", number);
    }

    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

24

24 is even.
24 is even.
-
Test Case 2

-25

-25 is odd.
-25 is odd.
-


Week-03 Practice Program-04

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

Your last recorded submission was on 2026-08-10, 20:14 IST.

Q.

Write a C Program to find the Largest Number (integer) among Three Numbers (integers) using IF and Logical && operator.

[Week 3 programming assignments will not be considered for final evaluation]

Complete Program

C
#include <stdio.h>

int main() {
    int n1, n2, n3;
    scanf("%d %d %d", &n1, &n2, &n3);

    // --- START OF SOLUTION CODE ---
    if (n1 >= n2 && n1 >= n3) {
        printf("%d is the largest number.", n1);
    } else if (n2 >= n1 && n2 >= n3) {
        printf("%d is the largest number.", n2);
    } else {
        printf("%d is the largest number.", n3);
    }

    return 0;
    // --- END OF SOLUTION CODE ---
}

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    if (n1 >= n2 && n1 >= n3) {
        printf("%d is the largest number.", n1);
    } else if (n2 >= n1 && n2 >= n3) {
        printf("%d is the largest number.", n2);
    } else {
        printf("%d is the largest number.", n3);
    }

    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

45 34 67

67 is the largest number.
67 is the largest number.
-
Test Case 2

80 -5 3

80 is the largest number.
80 is the largest number.
-





Week-04 Program-01

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

Q.

Write a program to find the factorial of a given number using while loop.

Complete Program

C
#include<stdio.h>
void main()
{
    int n;
    long int fact;  /* n is the number whose factorial we have to find and fact is the factorial */
    scanf("%d",&n);  /* The value of n is taken from test cases */
/* complete the program. Use the printf statements in the format mentioned below 
to match your output exactly with output test cases 
printf("The Factorial of %d is : %ld",n,fact);
You can declare any other variables if required */

    // --- START OF SOLUTION CODE ---
    int temp = n;
    fact = 1;

    while (temp > 1)
    {
        fact = fact * temp;
        temp--;
    }

    printf("The Factorial of %d is : %ld", n, fact);
}
// --- END OF SOLUTION CODE ---

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    int temp = n;
    fact = 1;

    while (temp > 1)
    {
        fact = fact * temp;
        temp--;
    }

    printf("The Factorial of %d is : %ld", n, 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

5

The Factorial of 5 is : 120
The Factorial of 5 is : 120
-
Test Case 2

10

The Factorial of 10 is : 3628800
The Factorial of 10 is : 3628800
-


Week-04: Program-02

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

Q.

Write a Program to find the sum of all even numbers from 1 to N where the value of N is taken as input. [For example when N is 10 then the sum is 2+4+6+8+10 = 30]

Complete Program

C
#include <stdio.h>  
void main()
{
int N, sum=0; 
scanf("%d", &N); /* The value of N is taken from the test cases */
/* Complete the program. Please use the printf statement given below to 
exactly match your output with the test cases.
printf("Sum = %d", sum);
*/

// --- START OF SOLUTION CODE ---
    int i;
    for (i = 2; i <= N; i += 2)
    {
        sum += i;
    }
    printf("Sum = %d", sum);
}
// --- END OF SOLUTION CODE ---

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    int i;
    for (i = 2; i <= N; i += 2)
    {
        sum += i;
    }
    printf("Sum = %d", sum);
}
// --- 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

10

Sum = 30
Sum = 30
-
Test Case 2

30

Sum = 240
Sum = 240
-


Week-04: Program-03

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

Q.

Write a C program to find power of a number using while loops. The base number (>0) and exponent (>=0) is taken from the test cases.

Complete Program

C
#include <stdio.h>
int main()
{
int base, exponent;
long int result;
scanf("%d", &base); //The base value is taken from test case
scanf("%d", &exponent);  //The exponent value is taken from test case

// --- START OF SOLUTION CODE ---
    int exp = exponent;
    result = 1;

    while (exp > 0)
    {
        result = result * base;
        exp--;
    }
// --- END OF SOLUTION CODE ---

printf("The result is : %ld", result);
return 0;
}

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    int exp = exponent;
    result = 1;

    while (exp > 0)
    {
        result = result * base;
        exp--;
    }
// --- 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 4

The result is : 625
The result is : 625
-
Test Case 2

7 3

The result is : 343
The result is : 343
-


Week-04 Program-04

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

Q.

Write a C program to calculate the Sum of First and the Last Digit of a given Number. For example if the number is 1234 the result is 1+4 = 5.

Complete Program

C
#include <stdio.h>
int main()
{
int N, First_digit, Last_digit;
scanf("%d", &N); //The number is accepted from the test case

// --- START OF SOLUTION CODE ---
    Last_digit = N % 10;
    First_digit = N;

    while (First_digit >= 10)
    {
        First_digit = First_digit / 10;
    }
// --- END OF SOLUTION CODE ---

printf("Sum of First and Last digit = %d", First_digit + Last_digit);
return 0;
}

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    Last_digit = N % 10;
    First_digit = N;

    while (First_digit >= 10)
    {
        First_digit = First_digit / 10;
    }
// --- 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

2908

Sum of First and Last digit = 10
Sum of First and Last digit = 10
-
Test Case 2

56986

Sum of First and Last digit = 11
Sum of First and Last digit = 11
-




Week-05 Problem-01

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

Q.

Write a C program to check whether a given number (N) is a perfect number or not? [Perfect Number - A perfect number is a positive integer number which is equals to the sum of its proper positive divisors. For example 6 is a perfect number because its proper divisors are 1, 2, 3 and it’s sum is equals to 6.]

Complete Program

C
#include <stdio.h>
int main()
{
    int N; 
    scanf("%d",&N); /* An integer number taken as input from test cases */
/*Complete the program by writing the rest of the code in the space provided.
Please copy and paste the printf statement given below wherever required
printf("%d is a perfect number.",N);
printf("%d is not a perfect number.",N);
*/

    // --- START OF SOLUTION CODE ---
    int sum = 0;
    for (int i = 1; i < N; i++)
    {
        if (N % i == 0)
        {
            sum += i;
        }
    }

    if (sum == N && N > 0)
    {
        printf("%d is a perfect number.", N);
    }
    else
    {
        printf("%d is not a perfect number.", N);
    }

    return 0;
}
// --- END OF SOLUTION CODE ---

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    int sum = 0;
    for (int i = 1; i < N; i++)
    {
        if (N % i == 0)
        {
            sum += i;
        }
    }

    if (sum == N && N > 0)
    {
        printf("%d is a perfect number.", N);
    }
    else
    {
        printf("%d is not a perfect number.", N);
    }

    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

6

6 is a perfect number.
6 is a perfect number.
-
Test Case 2

87

87 is not a perfect number.
87 is not a perfect number.
-


Week-05 Problem-02

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

Q.

Write a C program to count total number of digits of an Integer number (N).

Complete Program

C
#include <stdio.h>
 int main()
{
    int N; 
    scanf("%d",&N); /*The number is accepted from the test case data*/
/* Complete the rest of the code. Please use the printf statements as below
by just changing the variables used in your program 
printf("The number %d contains %d digits.",N,count);
*/

    // --- START OF SOLUTION CODE ---
    int count = 0;
    int temp = N;

    do {
        count++;
        temp /= 10;
    } while (temp != 0);

    printf("The number %d contains %d digits.", N, count);
    return 0;
}
// --- END OF SOLUTION CODE ---

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    int count = 0;
    int temp = N;

    do {
        count++;
        temp /= 10;
    } while (temp != 0);

    printf("The number %d contains %d digits.", N, count);
    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

3456

The number 3456 contains 4 digits.
The number 3456 contains 4 digits.
-
Test Case 2

30001

The number 30001 contains 5 digits.
The number 30001 contains 5 digits.
-


Week-05 Problem-03

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

Q.

Write a C program to check whether the given number(N) can be expressed as Power of Two (2) or not.
For example 8 can be expressed as 2^3.

Complete Program

C
#include <stdio.h>
int main()
{
    int N;
    scanf("%d",&N); /* The value of N is taken from the test case data */

/* Complete the code.
Use the printf statements as below
printf("%d is a number that can be expressed as power of 2.",N);
printf("%d cannot be expressed as power of 2.",N);
*/

    // --- START OF SOLUTION CODE ---
    int temp = N;
    int flag = 1;

    if (temp <= 0)
    {
        flag = 0;
    }
    else
    {
        while (temp > 1)
        {
            if (temp % 2 != 0)
            {
                flag = 0;
                break;
            }
            temp = temp / 2;
        }
    }

    if (flag == 1)
    {
        printf("%d is a number that can be expressed as power of 2.", N);
    }
    else
    {
        printf("%d cannot be expressed as power of 2.", N);
    }

    return 0;
}
// --- END OF SOLUTION CODE ---

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    int temp = N;
    int flag = 1;

    if (temp <= 0)
    {
        flag = 0;
    }
    else
    {
        while (temp > 1)
        {
            if (temp % 2 != 0)
            {
                flag = 0;
                break;
            }
            temp = temp / 2;
        }
    }

    if (flag == 1)
    {
        printf("%d is a number that can be expressed as power of 2.", N);
    }
    else
    {
        printf("%d cannot be expressed as power of 2.", N);
    }

    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

8

8 is a number that can be expressed as power of 2.
8 is a number that can be expressed as power of 2.
-
Test Case 2

46

46 cannot be expressed as power of 2.
46 cannot be expressed as power of 2.
-



Week-05 Problem-04

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

Q.

Write a C program to find sum of following series where the value of N is taken as input
1+ 1/2 + 1/3 + 1/4 + 1/5 + .. 1/N

Complete Program

C
#include<stdio.h>
int main()
{
int N;
float sum = 0.0;
scanf("%d",&N); /*Read the value of N from test cases provided*/
/* Complete the program. Please use the printf statement given below:
printf("Sum of the series is: %.2f\n",sum);
*/

// --- START OF SOLUTION CODE ---
    int i;
    for (i = 1; i <= N; i++)
    {
        sum += 1.0 / i;
    }

    printf("Sum of the series is: %.2f\n", sum);
    return 0;
}
// --- END OF SOLUTION CODE ---

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    int i;
    for (i = 1; i <= N; i++)
    {
        sum += 1.0 / i;
    }

    printf("Sum of the series is: %.2f\n", sum);
    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

6

Sum of the series is: 2.45
Sum of the series is: 2.45\n
Presentation Error
Test Case 2

50

Sum of the series is: 4.50
Sum of the series is: 4.50\n
Presentation Error



Week-06 Program-01

Due date on 2026-09-03, 23:59 IST

Q.

Write a C Program to find Largest Element of an Integer Array.
 Here the number of elements in the array ‘n’ and the elements of the array is read from the test data.
 Use the printf statement given below to print the largest element.
printf("Largest element = %d", largest);

Complete Program

C
#include <stdio.h>

int main()
{
    int i, n, largest;
    int arr[100];
    scanf("%d", &n); /*Accepts total number of elements from the test data */
    for(i = 0; i < n; ++i)
    {
       scanf("%d", &arr[i]); /* Accepts the array element from test data */
    }

    // --- START OF SOLUTION CODE ---
    largest = arr[0];
    for (i = 1; i < n; ++i)
    {
        if (arr[i] > largest)
        {
            largest = arr[i];
        }
    }
    printf("Largest element = %d", largest);

    return 0;
}
// --- END OF SOLUTION CODE ---

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    largest = arr[0];
    for (i = 1; i < n; ++i)
    {
        if (arr[i] > largest)
        {
            largest = arr[i];
        }
    }
    printf("Largest element = %d", largest);

    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

5 10 50 40 30 20

Largest element = 50
Largest element = 50
-
Test Case 2

7 100 50 60 70 90 30 40

Largest element = 100
Largest element = 100
-
Week-06 Program-02

Due date on 2026-09-03, 23:59 IST

Your last recorded submission was on 2026-08-22, 13:43 IST.

Q.

Write a C Program to print the array elements in reverse order (Not reverse sorted order. Just the last element will become first element, second last element will become second element and so on)
Here the size of the array, ‘n’ and the array elements is accepted from the test case data. The last part i.e. printing the array is also written.
You have to complete the program so that it prints in the reverse order.

Complete Program

C
#include<stdio.h>
 
int main() {
   int arr[20], i, n;
 
   scanf("%d", &n); /* Accepts the number of elements in the array */
   for (i = 0; i < n; i++) 
      scanf("%d", &arr[i]); /*Accepts the elements of the array */

   // --- START OF SOLUTION CODE ---
   int temp;
   for (i = 0; i < n / 2; i++) {
       temp = arr[i];
       arr[i] = arr[n - 1 - i];
       arr[n - 1 - i] = temp;
   }
   // --- END OF SOLUTION CODE ---

   for (i = 0; i < n; i++) {
      printf("%d\n", arr[i]); // For printing the array elements 
   }
 
   return (0);
}

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
   int temp;
   for (i = 0; i < n / 2; i++) {
       temp = arr[i];
       arr[i] = arr[n - 1 - i];
       arr[n - 1 - i] = temp;
   }
// --- 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 1 2 3 4 5

5\n
4\n
3\n
2\n
1
5\n
4\n
3\n
2\n
1\n
Presentation Error
Test Case 2

4 45 65 35 25

25\n
35\n
65\n
45
25\n
35\n
65\n
45\n
Presentation Error


Week-06 Program-03

Due date on 2026-09-03, 23:59 IST

Your last recorded submission was on 2026-08-22, 13:50 IST.

Q.

Write a C program to read Two One Dimensional Arrays of same data type (integer type) and merge them into another One Dimensional Array of same type.


Complete Program

C
#include<stdio.h>
int main() 
{
   int arr1[20], arr2[20], array_new[40], n1, n2, size, i;
 /*n1 size of first array (i.e. arr1[]), n2 size of second array(i.e. arr2[]), 
   size is the total size of the new array (array_new[]) */
 
   scanf("%d", &n1); //Get the size of first array from test data and store it in n1.
   
   for (i = 0; i < n1; i++)
      scanf("%d", &arr1[i]); //Accepts the values for first array 
 
   scanf("%d", &n2); //Get the size of second array from test data and store it in n2.
   
   for (i = 0; i < n2; i++)
      scanf("%d", &arr2[i]); //Accepts the values for second array

   // --- START OF SOLUTION CODE ---
   int j;
   for (i = 0; i < n1; ++i)
      array_new[i] = arr1[i];
   size = n1 + n2;
   for (i = 0, j = n1; j < size && i < n2; ++i, ++j)
      array_new[j] = arr2[i];
   // --- END OF SOLUTION CODE ---

   //Printing after merging
   for (i = 0; i < size; i++) {
      printf("%d\n", array_new[i]);
   }

   return 0;
}

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
int j;
for (i = 0; i < n1; ++i)
   array_new[i] = arr1[i];
size = n1 + n2;
for (i = 0, j = n1; j < size && i < n2; ++i, ++j)
   array_new[j] = arr2[i];
// --- 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 10 20 30 4 40 50 60 70

10\n
20\n
30\n
40\n
50\n
60\n
70
10\n
20\n
30\n
40\n
50\n
60\n
70\n
Presentation Error
Test Case 2

4 9 7 6 5 2 30 50

9\n
7\n
6\n
5\n
30\n
50
9\n
7\n
6\n
5\n
30\n
50\n
Presentation Error
Week-06 Program-04

Due date on 2026-09-03, 23:59 IST

Your last recorded submission was on 2026-08-22, 13:54 IST.

Q.

Write a C Program to delete duplicate elements from an array of integers.

Complete Program

C
#include<stdio.h>

int main() 
{
   int array[50], i, size;

   scanf("%d", &size); /*Accepts the size of array from test case data */
   for (i = 0; i < size; i++)
      scanf("%d", &array[i]); /* Read the array elements from the test case data */

   // --- START OF SOLUTION CODE ---
   int j, k;
   for (i = 0; i < size; i++) {
      for (j = i + 1; j < size;) {
         if (array[j] == array[i]) {
            for (k = j; k < size; k++) {
               array[k] = array[k + 1];
            }
            size--;
         } else
            j++;
      }
   }
   // --- END OF SOLUTION CODE ---

   for (i = 0; i < size; i++) {
      printf("%d\n", array[i]);
   }

   return 0;
}

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
int j, k;
   for (i = 0; i < size; i++) {
      for (j = i + 1; j < size;) {
         if (array[j] == array[i]) {
            for (k = j; k < size; k++) {
               array[k] = array[k + 1];
            }
            size--;
         } else
            j++;
      }
   }
// --- 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 50 60 30 20 30

50\n
60\n
30\n
20
50\n
60\n
30\n
20\n
Presentation Error
Test Case 2

6 40 20 50 30 20 10

40\n
20\n
50\n
30\n
10
40\n
20\n
50\n
30\n
10\n
Presentation Error


Week-07 Program-01

Due date on 2026-09-10, 23:59 IST

Your last recorded submission was on 2026-08-29, 12:05 IST.

Q.

Write a C Program to Count Number of Uppercase and Lowercase Letters in a given string. The given string may be a word or a sentence.

Complete Program

C
#include<stdio.h>
int main() {
   int upper = 0, lower = 0;
   char ch[100];
   scanf(" %[^\n]s", ch);  /*A word or a sentence is accepted from test case data */
/* Complete the remaining part of the code to store number of uppercase letters
in the variable upper and lowercase letters in variable lower.
The print part of already written. You can declare any variable if necessary */

   // --- START OF SOLUTION CODE ---
   int i = 0;
   while (ch[i] != '\0') {
       if (ch[i] >= 'A' && ch[i] <= 'Z') {
           upper++;
       } else if (ch[i] >= 'a' && ch[i] <= 'z') {
           lower++;
       }
       i++;
   }
   // --- END OF SOLUTION CODE ---

   printf("Uppercase Letters : %d\n", upper); /*prints number of uppercase letters */
   printf("Lowercase Letters : %d", lower); /*prints number of lowercase letters */

   return (0);
}

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
   int i = 0;
   while (ch[i] != '\0') {
       if (ch[i] >= 'A' && ch[i] <= 'Z') {
           upper++;
       } else if (ch[i] >= 'a' && ch[i] <= 'z') {
           lower++;
       }
       i++;
   }
// --- 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

Online NPTEL Course.

Uppercase Letters : 7\n
Lowercase Letters : 10
Uppercase Letters : 7\n
Lowercase Letters : 10
-
Test Case 2

National Programme on Technology Enhanced Learning is a joint initiative of the IITs and IISc.

Uppercase Letters : 11\n
Lowercase Letters : 68
Uppercase Letters : 11\n
Lowercase Letters : 68
-


Week-07 Program-02

Due date on 2026-09-10, 23:59 IST

Your last recorded submission was on 2026-08-29, 12:19 IST.

Q.

Complete Program

C
#include <stdio.h>
int main()
{
    int matrix[20][20];
    int i,j,r,c;
    scanf("%d",&r); //Accepts number of rows
    scanf("%d",&c); //Accepts number of columns 
    for(i=0;i< r;i++) //Accepts the matrix elements from the test case data
    {
        for(j=0;j< c;j++)
        {
            scanf("%d",&matrix[i][j]); 
        }
    }
/*Complete the code to print the sum of each rows. Use the printf() statement as
 printf("%d\n",sum); Where sum is the sum of a row. 
*/

    // --- START OF SOLUTION CODE ---
    int sum;
    for(i=0;i< r;i++)
    {
        sum=0;      
        for(j=0;j< c;j++)
        {
            sum += matrix[i][j];
        }
        printf("%d\n",sum);
    }
    return 0;
}
    // --- END OF SOLUTION CODE ---

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    int sum;
    for(i=0;i< r;i++)
    {
        sum=0;      
        for(j=0;j< c;j++)
        {
            sum += matrix[i][j];
        }
        printf("%d\n",sum);
    }
    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

3 3 1 1 1 2 2 2 3 3 3

3\n
6\n
9
3\n
6\n
9\n
Presentation Error
Test Case 2

2 3 1 2 3 4 5 6

6\n
15
6\n
15\n
Presentation Error


Week-07 Program-03

Due date on 2026-09-10, 23:59 IST

Your last recorded submission was on 2026-08-29, 12:20 IST.

Q.

Complete Program

C
#include <stdio.h>
int main()
{
    int matrix_A[20][20], matrix_B[20][20], matrix_C[20][20];
    int i,j,row,col;
    scanf("%d",&row); //Accepts number of rows
    scanf("%d",&col); //Accepts number of columns 
 
    /* Elements of first matrix are accepted from test data */
    for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++)
        {
            scanf("%d", &matrix_A[i][j]);
        }
    }
     /* Elements of second matrix are accepted from test data */
    
    for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++)
        {
            scanf("%d", &matrix_B[i][j]);
        }
    }
/* Complete the program to get the desired output. Use printf() statement as below
    printf("%d ", matrix_C[i][j]); You can declare your own variables if required. 
*/

    // --- START OF SOLUTION CODE ---
    for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++)
        {
            matrix_C[i][j] = matrix_A[i][j] - matrix_B[i][j];
        }
    }
    for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++)
        {
            printf("%d ", matrix_C[i][j]);
        }
        printf("\n");
    }
    return 0;
}
    // --- END OF SOLUTION CODE ---

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
    for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++)
        {
            matrix_C[i][j] = matrix_A[i][j] - matrix_B[i][j];
        }
    }
    for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++)
        {
            printf("%d ", matrix_C[i][j]);
        }
        printf("\n");
    }
    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: 1/1 Passed

Note: These tests may not be considered while scoring.

Public Test Cases

Test Case
Input
Expected Output
Output
Status
Test Case 1

3 3 2 3 5 4 5 6 6 5 7 1 5 2 2 3 4 3 3 4

1 -2 3 \n
2 2 2 \n
3 2 3
1 -2 3 \n
2 2 2 \n
3 2 3 \n
Presentation Error


Week-07 Program-04

Due date on 2026-09-10, 23:59 IST

Your last recorded submission was on 2026-08-29, 12:22 IST.

Q.

Write a C program to print Largest and Smallest Word from a given sentence. If there are two or more words of same length, then the first one is considered. A single letter in the sentence is also consider as a word.

Complete Program

C
#include<stdio.h>
#include<string.h>
int main()
{
    char str[100]={0},substr[100][100]={0}; 
//str[100] is for storing the sentence and substr[50][50] is for storing each word.
    
scanf("%[^\n]s", str); //Accepts the sentence from the test case data.
/* Complete the program to get the desired output.
The print statement should be as below
 
printf("Largest Word is: %s\nSmallest word is: %s\n", -------,--------);
*/

    // --- START OF SOLUTION CODE ---
    int i=0,j=0,k=0,a,minIndex=0,maxIndex=0,max=0,min=0;
    char c; 
    while(str[k]!='\0')  //for splitting sentence into words 
    {
        j=0;
        while(str[k]!=' '&&str[k]!='\0' && str[k]!='.')
        {
            substr[i][j]=str[k];
            k++;
            j++;
        }
        substr[i][j]='\0';
        i++;
        if(str[k]!='\0')
        {
            k++;
        }        
    }
    int len=i;
    max=strlen(substr[0]);
    min=strlen(substr[0]);

    //After splitting getting length of string and finding its index having max length and index having min length
    for(a=1; a<len; a++)
    {
        if(strlen(substr[a]) > max)
        {
            max = strlen(substr[a]);
            maxIndex = a;
        }
        if(strlen(substr[a]) < min)
        {
            min = strlen(substr[a]);
            minIndex = a;
        }
    }

    printf("Largest Word is: %s\nSmallest word is: %s\n", substr[maxIndex], substr[minIndex]);
    return 0;
}
    // --- END OF SOLUTION CODE ---

Code Snippet to Paste in the Editor

C
// --- START OF SOLUTION CODE ---
int i=0,j=0,k=0,a,minIndex=0,maxIndex=0,max=0,min=0;
char c; 
while(str[k]!='\0')  //for splitting sentence into words 
    {
        j=0;
        while(str[k]!=' '&&str[k]!='\0' && str[k]!='.')
        {
            substr[i][j]=str[k];
            k++;
            j++;
        }
        substr[i][j]='\0';
        i++;
        if(str[k]!='\0')
        {
            k++;
        }        
    }
    int len=i;
    max=strlen(substr[0]);
    min=strlen(substr[0]);

    //After splitting getting length of string and finding its index having max length and index having min length
    for(a=1; a<len; a++)
    {
        if(strlen(substr[a]) > max)
        {
            max = strlen(substr[a]);
            maxIndex = a;
        }
        if(strlen(substr[a]) < min)
        {
            min = strlen(substr[a]);
            minIndex = a;
        }
    }

    printf("Largest Word is: %s\nSmallest word is: %s\n", substr[maxIndex], substr[minIndex]);
    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

Problem Solving through Programming in C.

Largest Word is: Programming\n
Smallest word is: C
Largest Word is: Programming\n
Smallest word is: C\n
Presentation Error
Test Case 2

NPTEL is a joint initiative of the IITs and IISc.

Largest Word is: initiative\n
Smallest word is: a
Largest Word is: initiative\n
Smallest word is: a\n
Presentation Error





















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.