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 | Jan-2024 Week 4 to 8


NPTEL » Problem Solving Through Programming In C


  Please scroll down for latest Programs ðŸ‘‡ 




Practice Program - 1

Due on 2024-02-22, 23:59 IST
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.

[This Programming assignments will not be evaluated. This is for users to get familiar with programming in google course builder platform]
Select the Language for this assignment. 
1
#include <stdio.h>
2
#define PI 3.14
3
void main()
4
{
5
    int radius;
6
    float area;
7
    /* Enter the radius of a circle */
8
    scanf("%d", &radius);
9
10
/*Here the first part and the last part of the program is already written. 
11
You have to write only the middle portion by carefully considering the
12
variables used. You can use more variables if required but no other input and output
13
statements can be used as the test input and corresponding output is already provided. 
14
There are two public test cases which you can see and check whether your program is correct. 
15
There is also one or two private test cases, the result of which you cannot
16
see and which are used for evaluation purpose*/ 
17
/*For example in this program the middle part can be written as:
18
area = PI * radius * radius;  
19
in the space provided */
20
area = PI * radius * radius;
21
printf("Area of a circle = %5.2f", area);
0
}
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
7
Area of a circle = 153.86
Area of a circle = 153.86
Passed
Test Case 2
50
Area of a circle = 7850.00
Area of a circle = 7850.00
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed


Practice Program - 2

Due on 2024-02-22, 23:59 IST
Write a C program to check if a given Number is zero or Positive or Negative Using if...else statement.

[This Programming assignments will not be evaluated. This is for users to get familiar with programming in google course builder platform]
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
    double number;
5
    scanf("%lf", &number); 
6
    /* The number is entered automatically from the test cases and executed */
7
    /* Write the rest of the code in the box below
8
    As the output should exactly match with the output mentioned in the test cases
9
    so copy and paste the following printf statements wherever and whichever is applicable
10
      printf("The number is 0.");
11
      printf("Negative number.");
12
      printf("Positive number.");  
13
    Do not use any other scanf statements */
14
if (number <= 0.0)
15
    {
16
        if (number == 0.0)
17
            printf("The number is 0.");
18
        else
19
            printf("Negative number.");
20
    }
21
    else
22
        printf("Positive number.");
23
}
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
14.05
Positive number.
Positive number.
Passed
Test Case 2
0.45
Positive number.
Positive number.
Passed
Test Case 3
-50
Negative number.
Negative number.
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed





Week-04: Program-01

Due on 2024-02-22, 23:59 IST
Write a C Program to Find the Smallest Number among Three Numbers (integer values) using Nested IF-Else statement.
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
    int n1, n2, n3; 
5
    scanf("%d %d %d", &n1, &n2, &n3); /* where three number are read from the test cases and are stored in the variable n1, n2 and n3 */
6
7
/* Complete the program to get the desired output */
8
/* Only use the printf statement given below to exactly match your output 
9
with the output cases. Change the variable n1 as required.
10
11
printf("%d is the smallest number.", n1);    //Copy and paste this printf statement wherever required. 
12
13
*/
14
if (n1<n2)
15
    {
16
        if(n1<n3)
17
            printf("%d is the smallest number.", n1);
18
        else
19
            printf("%d is the smallest number.", n3);
20
    }
21
    else
22
    {
23
        if(n2<n3)
24
            printf("%d is the smallest number.", n2);
25
        else
26
            printf("%d is the smallest number.", n3);
27
    }
28
}
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
20 30 10
10 is the smallest number.
10 is the smallest number.
Passed
Test Case 2
77 44 99
44 is the smallest number.
44 is the smallest number.
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed


Week-04: Program-02

Due on 2024-02-22, 23:59 IST
The length of three sides are taken as input. Write a C program to find whether a triangle can be formed or not. If not display “This Triangle is NOT possible.” If the triangle can be formed then check whether the triangle formed is equilateral, isosceles, scalene or a right-angled triangle. (If it is a right-angled triangle then only print Right-angle triangle do not print it as Scalene Triangle).
Select the Language for this assignment. 
1
#include<stdio.h>
2
int main()
3
{
4
    int a,b,c; 
5
    scanf("%d %d %d",&a, &b, &c); /*The length of three sides are entered from the test cases */
6
 
7
/* Complete the program. Copy and paste from the printf statements mentioned below wherever required for printing the outputs 
8
9
printf("Triangle is not possible");
10
printf("Right-angle Triangle");
11
printf("Isosceles Triangle");
12
printf("Equilateral Triangle");
13
printf("Scalene Triangle");
14
15
*/
16
if(a<(b+c)&&b<(a+c)&&c<(a+b))
17
    {
18
        if(a==b&&a==c&&b==c)
19
        printf("Equilateral Triangle");
20
          else if(a==b||a==c||b==c)
21
          printf("Isosceles Triangle");
22
          else   
23
    if((a*a)==(b*b)+(c*c)||(b*b)==(a*a)+(c*c)||(c*c)==(a*a)+(b*b))
24
        printf("Right-angle Triangle");
25
        else if(a!=b&&a!=c&&b!=c)
26
        printf("Scalene Triangle");
27
    }
28
    else
29
    printf("Triangle is not possible");
30
}
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
10 4 6
Triangle is not possible
Triangle is not possible
Passed
Test Case 2
7 6 8
Scalene Triangle
Scalene Triangle
Passed
Test Case 3
3 4 5
Right-angle Triangle
Right-angle Triangle
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed


Week-04 Program-03

Due on 2024-02-22, 23:59 IST
Write a program to find the factorial of a given number using while loop.
Your last recorded submission was on 2024-02-09, 20:35 IST
Select the Language for this assignment. 
1
#include<stdio.h>
2
void main()
3
{
4
    int n;
5
    long int fact;  /* n is the number whose factorial we have to find and fact is the factorial */
6
    scanf("%d",&n);  /* The value of n is taken from test cases */
7
8
/* complete the program. Use the printf statements in the format mentioned below 
9
to match your output exactly with output test cases 
10
11
printf("The Factorial of %d is : %ld",n,fact);
12
13
You can declare any other variables if required */
14
int i=1;
15
fact = 1;
16
while(i<=n)
17
    {
18
        fact*=i;
19
        i++;
20
    }
21
    printf("The Factorial of %d is : %ld",n,fact);
22
}
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
The Factorial of 5 is : 120
The Factorial of 5 is : 120
Passed
Test Case 2
10
The Factorial of 10 is : 3628800
The Factorial of 10 is : 3628800
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed



Week-04: Program-04

Due on 2024-02-22, 23:59 IST
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]
Select the Language for this assignment. 
1
#include <stdio.h>  
2
void main()
3
{
4
int N, sum=0; 
5
scanf("%d", &N); /* The value of N is taken from the test cases */
6
7
/* Complete the program. Please use the printf statement given below to 
8
exactly match your output with the test cases.
9
10
printf("Sum = %d", sum);
11
12
*/
13
for(int i=2; i <= N; i=i+2)
14
  sum+=i;
15
printf("Sum = %d", sum);
16
}
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
10
Sum = 30
Sum = 30
Passed
Test Case 2
30
Sum = 240
Sum = 240
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed









Week-05 Problem-01

Due on 2024-02-22, 23:59 IST
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.]
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
    int N; 
5
    scanf("%d",&N); /* An integer number taken as input from test cases */
6
7
/*Complete the program by writing the rest of the code in the space provided.
8
9
Please copy and paste the printf statement given below wherever required
10
printf("\n%d is a perfect number.",N);
11
printf("\n%d is not a perfect number.",N);
12
*/
13
int i, sum=0;
14
    for(i=1; i<N;i++)
15
    {
16
        if(N%i==0)
17
            sum+=i;
18
    }
19
 
20
    if(sum==N)
21
        printf("\n%d is a perfect number.",N);
22
    else
23
        printf("\n%d is not a perfect number.",N);
24
}
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
6
6 is a perfect number.
\n
6 is a perfect number.
Passed after ignoring Presentation Error
Test Case 2
87
87 is not a perfect number.
\n
87 is not a perfect number.
Passed after ignoring Presentation Error





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed




Week-05 Problem-02

Due on 2024-02-22, 23:59 IST
Write a C program to count total number of digits of an Integer number (N).
Select the Language for this assignment. 
1
#include <stdio.h>
2
 int main()
3
{
4
    int N; 
5
    scanf("%d",&N); /*The number is accepted from the test case data*/
6
7
/* Complete the rest of the code. Please use the printf statements as below
8
by just changing the variables used in your program 
9
10
printf("The number %d contains %d digits.",N,count);
11
12
*/
13
int temp, count; 
14
count=0;
15
    temp=N;
16
    while(temp>0)
17
    {
18
        count++;
19
        temp/=10;
20
    }
21
     printf("The number %d contains %d digits.",N,count);
22
}
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
3456
The number 3456 contains 4 digits.
The number 3456 contains 4 digits.
Passed
Test Case 2
30001
The number 30001 contains 5 digits.
The number 30001 contains 5 digits.
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed




Week-05 Problem-03

Due on 2024-02-22, 23:59 IST
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.
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
    int N;
5
    scanf("%d",&N); /* The value of N is taken from the test case data */
6
 
7
/* Complete the code.
8
Use the printf statements as below
9
printf("%d is a number that can be expressed as power of 2.",N);
10
printf("%d cannot be expressed as power of 2.",N);
11
*/
12
int temp, flag;
13
    temp=N;
14
    flag=0;
15
   
16
    while(temp!=1)
17
    {
18
        if(temp%2!=0){
19
            flag=1;
20
            break;
21
        }
22
        temp=temp/2;
23
    }
24
  
25
    if(flag==0)
26
        printf("%d is a number that can be expressed as power of 2.",N);
27
    else
28
        printf("%d cannot be expressed as power of 2.",N);
29
}
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
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.
Passed
Test Case 2
46
46 cannot be expressed as power of 2.
46 cannot be expressed as power of 2.
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed




Week-05 Problem-04

Due on 2024-02-22, 23:59 IST
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
Select the Language for this assignment. 
1
#include<stdio.h>
2
int main()
3
{
4
int N;
5
float sum = 0.0;
6
scanf("%d",&N); /*Read the value of N from test cases provided*/
7
8
/* Complete the program. Please use the printf statement given below:
9
10
printf("Sum of the series is: %.2f\n",sum);
11
12
*/
13
int i;
14
for(i=1;i<=N;i++)
15
sum = sum + ((float)1/(float)i);
16
printf("Sum of the series is: %.2f\n",sum);
17
}
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
6
Sum of the series is: 2.45
Sum of the series is: 2.45\n
Passed after ignoring Presentation Error
Test Case 2
50
Sum of the series is: 4.50
Sum of the series is: 4.50\n
Passed after ignoring Presentation Error





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed








Week 6 : Problem 01

Due on 2024-03-07, 23:59 IST
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);
Select the Language for this assignment. 
1
#include <stdio.h>
2
3
int main()
4
{
5
    int i, n, largest;
6
    int arr[100];
7
8
    scanf("%d", &n); /*Accepts total number of elements from the test data */
9
10
 for(i = 0; i < n; ++i)
11
    {
12
       scanf("%d", &arr[i]); /* Accepts the array element from test data */
13
    }
14
largest = arr[0];
15
for(i = 1; i < n; ++i)
16
    {
17
           if(largest < arr[i])
18
           largest = arr[i];
19
    }
20
    printf("Largest element = %d", largest);
21
22
    return 0;
23
}
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
10
50
40
30
20
Largest element = 50
Largest element = 50
Passed
Test Case 2
7
100
50
60
70
90
30
40
Largest element = 100
Largest element = 100
Passed





Week 6 : Problem 02

Due on 2024-03-07, 23:59 IST
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.
Select the Language for this assignment. 
1
#include<stdio.h>
2
 
3
int main() {
4
   int arr[20], i, n;
5
 
6
   scanf("%d", &n); /* Accepts the number of elements in the array */
7
8
  for (i = 0; i < n; i++) 
9
     scanf("%d", &arr[i]); /*Accepts the elements of the array */
10
int j, temp;  
11
j = i - 1;   // last Element of the array
12
i = 0;       // first element of the array
13
 
14
   while (i < j) {
15
      temp = arr[i];
16
      arr[i] = arr[j];
17
      arr[j] = temp;
18
      i++;             
19
      j--;        
20
   }
0
for (i = 0; i < n; i++) {
1
      printf("%d\n", arr[i]); // For printing the array elements 
2
   }
3
 
4
   return (0);
5
}
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
1
2
3
4
5
5\n
4\n
3\n
2\n
1
5\n
4\n
3\n
2\n
1\n
Passed after ignoring 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
Passed after ignoring Presentation Error





Week 6 : Problem 03

Due on 2024-03-07, 23:59 IST
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.
Select the Language for this assignment. 
1
#include<stdio.h>
2
int main() 
3
{
4
   int arr1[20], arr2[20], array_new[40], n1, n2, size, i;
5
 /*n1 size of first array (i.e. arr1[]), n2 size of second array(i.e. arr2[]), 
6
   size is the total size of the new array (array_new[]) */
7
 
8
   scanf("%d", &n1); //Get the size of first array from test data and store it in n1.
9
   
10
   for (i = 0; i < n1; i++)
11
      scanf("%d", &arr1[i]); //Accepts the values for first array 
12
 
13
   scanf("%d", &n2); //Get the size of second array from test data and store it in n2.
14
   
15
   for (i = 0; i < n2; i++)
16
      scanf("%d", &arr2[i]); //Accepts the values for second array
17
//Marge two arrays
18
int j;
19
for (i=0;i<n1;++i)
20
array_new[i]=arr1[i];
21
22
size =  n1 + n2;
23
24
for(i=0, j=n1; j<size && i<n2; ++i, ++j)
25
array_new[j] = arr2[i];
0
//Printing after merging
1
2
for (i = 0; i < size; i++) {
3
      printf("%d\n", array_new[i]);
4
   }
5
6
}
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
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
Passed after ignoring 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
Passed after ignoring Presentation Error




Week 6 : Problem 04

Due on 2024-03-07, 23:59 IST
Write a C Program to delete duplicate elements from an array of integers.
Select the Language for this assignment. 
1
#include<stdio.h>
2
 
3
int main() 
4
{
5
   int array[50], i, size;
6
 
7
   scanf("%d", &size); /*Accepts the size of array from test case data */
8
9
   for (i = 0; i < size; i++)
10
   scanf("%d", &array[i]); /* Read the array elements from the test case data */
11
int j, k;
12
   for (i = 0; i < size; i++) {
13
      for (j = i + 1; j < size;) {
14
         if (array[j] == array[i]) {
15
            for (k = j; k < size; k++) {
16
               array[k] = array[k + 1];
17
            }
18
            size--;
19
         } else
20
            j++;
21
      }
22
   }
0
for (i = 0; i < size; i++) {
1
      printf("%d\n", array[i]);
2
   }
3
4
}
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
50
60
30
20
30
50\n
60\n
30\n
20
50\n
60\n
30\n
20\n
Passed after ignoring 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
Passed after ignoring Presentation Error





Week-07 Program-01

Due on 2024-03-14, 23:59 IST
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.
Select the Language for this assignment. 
1
#include<stdio.h>
2
int main() {
3
   int upper = 0, lower = 0;
4
   char ch[100];
5
   scanf(" %[^\n]s", ch);  /*A word or a sentence is accepted from test case data */
6
7
/* Complete the remaining part of the code to store number of uppercase letters
8
in the variable upper and lowercase letters in variable lower.
9
The print part of already written. You can declare any variable if necessary */
10
int i = 0;
11
   while (ch[i] != '\0') {
12
      if (ch[i] >= 'A' && ch[i] <= 'Z')
13
         upper++;
14
      if (ch[i] >= 'a' && ch[i] <= 'z')
15
         lower++;
16
      i++;
17
   }
0
printf("Uppercase Letters : %d\n", upper); /*prints number of uppercase letters */
1
   printf("Lowercase Letters : %d", lower); /*prints number of lowercase letters */
2
 
3
   return (0);
4
}
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
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
Passed
Test Case 2
Problem Solving through Programming in C.
Uppercase Letters : 4\n
Lowercase Letters : 31
Uppercase Letters : 4\n
Lowercase Letters : 31
Passed




Week-07 Program-02

Due on 2024-03-14, 23:59 IST
Write a C program to find the sum of all elements of each row of a matrix.
 Example: For a matrix  4 5 6
 6 7 3
 1 2 3
 The output will be 15 16 6
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
    int matrix[20][20];
5
    int i,j,r,c;
6
7
    scanf("%d",&r); //Accepts number of rows
8
    scanf("%d",&c); //Accepts number of columns 
9
10
    for(i=0;i< r;i++) //Accepts the matrix elements from the test case data
11
    {
12
        for(j=0;j< c;j++)
13
        {
14
            scanf("%d",&matrix[i][j]); 
15
        }
16
    }
17
/*Complete the code to print the sum of each rows. Use the printf() statement as
18
 printf("%d\n",sum); Where sum is the sum of a row. 
19
*/
20
int sum;
21
    for(i=0;i< r;i++)
22
    {
23
        sum=0;      
24
        for(j=0;j< c;j++)
25
        {
26
          //  printf("%d\t",matrix[i][j]);   
27
            sum     +=  matrix[i][j];
28
        }
29
        printf("%d\n",sum);
30
    }
31
 
32
}
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
3
3
1
1
1
2
2
2
3
3
3
3\n
6\n
9
3\n
6\n
9\n
Passed after ignoring Presentation Error
Test Case 2
2
3
1
2
3
4
5
6
6\n
15
6\n
15\n
Passed after ignoring Presentation Error




Week-07 Program-03

Due on 2024-03-14, 23:59 IST
Write a C program to find subtraction of two matrices i.e. matrix_A - matrix_B=matrix_C.
If the given martix are
 2 3 5 and 1 5 2 Then the output will be 1 -2 3
 4 5 6   2 3 4  2 2 2
 6 5 7   3 3 4  3 2 3

The elements of the output matrix are separated by one blank space
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
    int matrix_A[20][20], matrix_B[20][20], matrix_C[20][20];
5
    int i,j,row,col;
6
    scanf("%d",&row); //Accepts number of rows
7
    scanf("%d",&col); //Accepts number of columns 
8
 
9
    /* Elements of first matrix are accepted from test data */
10
    for(i=0; i<row; i++)
11
    {
12
        for(j=0; j<col; j++)
13
        {
14
            scanf("%d", &matrix_A[i][j]);
15
        }
16
    }
17
18
     /* Elements of second matrix are accepted from test data */
19
    
20
    for(i=0; i<row; i++)
21
    {
22
        for(j=0; j<col; j++)
23
        {
24
            scanf("%d", &matrix_B[i][j]);
25
        }
26
    }
27
28
/* Complete the program to get the desired output. Use printf() statement as below
29
    printf("%d ", matrix_C[i][j]); You can declare your own variables if required. 
30
*/
31
/* 
32
    Subtract both matrices and store the result in matrix C
33
  */
34
   for(i=0; i<row; i++)
35
    {
36
        for(j=0; j<col; j++)
37
        {
38
    
39
            matrix_C[i][j] = matrix_A[i][j] - matrix_B[i][j];
40
        }
41
    }
42
43
     for(i=0; i<row; i++)
44
    {
45
        for(j=0; j<col; j++)
46
        {
47
            printf("%d ", matrix_C[i][j]);
48
        }
49
        printf("\n");
50
    }
51
52
    return 0;
53
}
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
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
Passed after ignoring Presentation Error




Week-07 Program-04

Due on 2024-03-14, 23:59 IST
Write a C program to print lower triangle of a square matrix.
For example the output of a given matrix
2 3 4   will be  2 0 0
5 6 7  5 6 0
4 5 6  4 5 6

Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
int matrix[20][20];
5
int i,j,r;
6
   
7
scanf("%d", &r); //Accepts number of rows or columns
8
9
    for(i=0;i< r;i++) //Accepts the matrix elements from the test case data
10
    {
11
        for(j=0;j<r; j++)
12
        {
13
            scanf("%d",&matrix[i][j]);
14
        }
15
    }
16
17
/* Complete the program to get the desired output. Use the printf() statement as
18
printf("%d ", matrix[i][j]);
19
*/
20
for(i=0; i<r; i++) {
21
        for(j=0; j<r; j++) {
22
            if(i>=j)
23
                printf("%d ", matrix[i][j]);
24
            else
25
                printf("%d ", 0);
26
        }
27
        printf("\n");
28
    }
29
return 0;
30
}
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
3
1
2
3
1
2
3
1
2
3
1 0 0 \n
1 2 0 \n
1 2 3
1 0 0 \n
1 2 0 \n
1 2 3 \n
Passed after ignoring Presentation Error







Week 08: Program-01

Due on 2024-03-21, 23:59 IST
Write a C Program to find HCF of 4 given numbers using recursive function
Select the Language for this assignment. 
1
#include<stdio.h>
2
int HCF(int, int); //You have to write this function which calculates the HCF. 
3
     
4
int main()
5
{
6
   int a, b, c, d, result;
7
   scanf("%d %d %d %d", &a, &b, &c, &d); /* Takes 4 number as input from the test data */
8
   result = HCF(HCF(a, b), HCF(c,d));
9
   printf("The HCF is %d", result);
10
}
11
12
//Complete the rest of the program to calculate HCF
13
int HCF(int x, int y)
14
{
15
   while (x != y)
16
   {
17
      if (x > y)
18
       {
19
           return HCF(x - y, y);
20
       }
21
       else
22
       {
23
       return HCF(x, y - x);
24
       }
25
    }
26
    return x;
27
}
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
100
30
50
70
The HCF is 10
The HCF is 10
Passed
Test Case 2
49
56
147
21
The HCF is 7
The HCF is 7
Passed



Week-08 Program-02

Due on 2024-03-21, 23:59 IST
Write a C Program to print Binary Equivalent of an Integer using Recursion
Select the Language for this assignment. 
1
#include <stdio.h>
2
int binary_conversion(int); //function to convert binary to decimal number
3
int main()
4
  {
5
  int num, bin;  //num is the decimal number and bin is the binary equivalent for the number
6
7
  scanf("%d", &num); //The decimal number is taken from the test case data
8
  bin = binary_conversion(num); //binary number is stored in variable bin
9
  printf("The binary equivalent of %d is %d", num, bin);
10
  return 0;
11
  }
12
int binary_conversion(int num)
13
  { 
14
     if (num == 0)
15
        {
16
            return 0;
17
        }
18
        else
19
        {
20
            return (num % 2) + 10 * binary_conversion(num / 2);
21
        }
22
  }
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
10
The binary equivalent of 10 is 1010
The binary equivalent of 10 is 1010
Passed
Test Case 2
257
The binary equivalent of 257 is 100000001
The binary equivalent of 257 is 100000001
Passed



Week-08 Program-03

Due on 2024-03-21, 23:59 IST
Write a C Program to reverse a given word using function.
e.g. INDIA should be printed as AIDNI
Select the Language for this assignment. 
1
#include<stdio.h>
2
#include<string.h>
3
4
void reverse(char[], int, int);
5
    int main()
6
    {
7
        char str1[20];
8
        scanf("%s", str1); //The string is taken as input form the test data. 
9
     
10
/* Complete the program to print the string in reverse order using the function
11
void reverse(char[], int, int);
12
Use the printf statement as
13
printf("The string after reversing is: %s\n", str1); 
14
You can use different variable also.
15
*/
16
reverse(str1, strlen(str1), 0);
17
        printf("The string after reversing is: %s", str1);
18
        return 0;
19
}
20
21
void reverse(char str1[], int len, int i)
22
{
23
  char temp;
24
  for(int i=0; i<len/2; i++)
25
  {
26
    temp = str1[i];
27
    str1[i] = str1[len-i-1];
28
    str1[len-i-1] = temp;
29
  }
30
  str1[len]='\0';
31
}
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
computer
The string after reversing is: retupmoc
The string after reversing is: retupmoc
Passed
Test Case 2
NPTEL
The string after reversing is: LETPN
The string after reversing is: LETPN
Passed



Week 08: Program-04

Due on 2024-03-21, 23:59 IST
Write a C Program to find power of a given number using recursion. The number and the power to be calculated is taken from test case
Select the Language for this assignment. 
1
#include <stdio.h>  
2
long power(int, int);
3
int main()
4
{
5
int pow, num;
6
long result;
7
8
scanf("%d", &num); //The number taken as input from test case data 
9
10
scanf("%d", &pow); //The power is taken from the test case 
11
result = power(num, pow);
12
printf("%d^%d is %ld", num, pow, result);
13
return 0;
14
}
15
long power(int num, int pow)
16
{
17
if (pow)
18
{
19
return (num * power(num, pow - 1));
20
}
21
return 1;
22
}
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
2
5^2 is 25
5^2 is 25
Passed
Test Case 2
10
4
10^4 is 10000
10^4 is 10000
Passed
































































































































































































































































2 comments:

  1. The programs of 9th week are not posted. Please post it as soon as possible

    ReplyDelete
    Replies
    1. It has been posted on different blog post. Follow this link : https://swayamsolver.blogspot.com/2024/03/problem-solving-through-programming-in-c-jan-2024-programs-week9to10.html

      Delete

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