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

NPTEL Problem Solving Through Programming In C - Programming Assignment | July-2024 Week 4 to 8



Week-04: Program-01

Due on 2024-08-22, 23:59 IST
Write a C Program to Find the Smallest Number among Three Numbers (integer values) using Nested IF-Else statement.
Your last recorded submission was on 2024-08-14, 18:29 IST
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




Week-04: Program-02

Due on 2024-08-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).
Your last recorded submission was on 2024-08-14, 18:31 IST
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 if((a*a)==(b*b)+(c*c)||(b*b)==(a*a)+(c*c)||(c*c)==(a*a)+(b*b))
23
        printf("Right-angle Triangle");
24
    else if((a!=b)&&(a!=c)&&(b!=c))
25
        printf("Scalene Triangle");
26
    }
27
else
28
    printf("Triangle is not possible");
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
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
9 9 9
Equilateral Triangle
Equilateral Triangle
Passed





Week-04 Program-03

Due on 2024-08-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-08-14, 18:32 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
fact = 1;
15
for(int i=n;i>0;i--)
16
  fact*=i;
17
printf("The Factorial of %d is : %ld",n,fact);
18
}
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




Week-04: Program-04

Due on 2024-08-22, 23:59 IST
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.
Your last recorded submission was on 2024-08-14, 18:33 IST
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
int base, exponent;
5
long int result;
6
scanf("%d", &base); //The base value is taken from test case
7
scanf("%d", &exponent);  //The exponent value is taken from test case
8
if(exponent == 0) 
9
   result = 1;
10
else
11
{
12
result = 1;
13
while(exponent != 0)
14
{
15
result = result * base;
16
--exponent;
17
}
18
}
0
printf("The result is : %ld\n", result);
1
return 0;
2
}
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
4
The result is : 625
The result is : 625\n
Passed after ignoring Presentation Error
Test Case 2
7
3
The result is : 343
The result is : 343\n
Passed after ignoring Presentation Error







Week-05 Program-01

Due on 2024-08-29, 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("%d is a perfect number.",N);
22
    else
23
        printf("%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.
6 is a perfect number.
Passed
Test Case 2
87
87 is not a perfect number.
87 is not a perfect number.
Passed




Week-05 Program-02

Due on 2024-08-29, 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
570
The number 570 contains 3 digits.
The number 570 contains 3 digits.
Passed





Week-05 Program-03

Due on 2024-08-29, 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




Week-05 Program-04

Due on 2024-08-29, 23:59 IST
Write a C program to print the following Pyramid pattern upto Nth row. Where N (number of rows to be printed) is taken as input. For example when the value of N is 5 the pyramid will be printed as follows
*****
****
***
**
*

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 as input from the test case */
6
int i,j;
7
for(i=N; i>0; i--)
8
  {
9
  for(j=0;j<i;j++)
10
    {
11
    printf("*");
12
    }
13
  printf("\n");
14
  } 
15
}
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
*****\n
****\n
***\n
**\n
*
*****\n
****\n
***\n
**\n
*\n
Passed after ignoring Presentation Error
Test Case 2
3
***\n
**\n
*
***\n
**\n
*\n
Passed after ignoring Presentation Error






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






Week-06 Program-01

Due on 2024-09-05, 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-06 Program-02

Due on 2024-09-05, 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
int main() {
3
   int arr[20], i, n;
4
 
5
   scanf("%d", &n); /* Accepts the number of elements in the array */
6
7
  for (i = 0; i < n; i++) 
8
     scanf("%d", &arr[i]); /*Accepts the elements of the array */
9
int j, temp;  
10
j = i - 1;   // last Element of the array
11
i = 0;       // first element of the array
12
 
13
   while (i < j) {
14
      temp = arr[i];
15
      arr[i] = arr[j];
16
      arr[j] = temp;
17
      i++;             
18
      j--;        
19
   }
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-06 Program-03

Due on 2024-09-05, 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];
26
//Printing after merging
0
for (i = 0; i < size; i++) {
1
      printf("%d\n", array_new[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
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-06 Program-04

Due on 2024-09-05, 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






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








Week 07 Program-01

Due on 2024-09-12, 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
Online NPTEL Course.
Uppercase Letters : 7\n
Lowercase Letters : 10
Uppercase Letters : 7\n
Lowercase Letters : 10
Passed
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
Passed






Week 07 Program-02

Due on 2024-09-12, 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-09-12, 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-09-12, 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-09-19, 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-09-19, 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




Week-08 Program-03

Due on 2024-09-19, 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\n", 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\n
Passed after ignoring Presentation Error
Test Case 2
257
The binary equivalent of 257 is 100000001
The binary equivalent of 257 is 100000001\n
Passed after ignoring Presentation Error




Week 08: Program-04

Due on 2024-09-19, 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-09 Program-01

Due on 2024-09-26, 23:59 IST
Write a program to print all the locations at which a particular element (taken as input) is found in a list and also print the total number of times it occurs in the list. The location starts from 1.
For example: if there are 4 elements in the array
5
6
5
7
If the element to search is 5 then the output will be
5 is present at location 1
5 is present at location 3
5 is present 2 times in the array.
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
   int array[100], search, n, count = 0;
5
   //"search" is the key element to search and 'n' is the total number of element of the array
6
   // "count" is to store total number of elements
7
8
 scanf("%d", &n); //Number of elements is taken from test case
9
10
 int c;
11
   for (c = 0; c < n; c++)
12
      scanf("%d", &array[c]);
13
14
   scanf("%d", &search); // The element to search is taken from test case
15
16
/* Use the printf statements as below:
17
"%d is present at location %d.\n"  for each locations
18
"%d is not present in the array.\n" if the element is not found in the list
19
"%d is present %d times in the array.\n"
20
*/
21
for (c = 0; c < n; c++)
22
    {
23
      if (array[c] == search)
24
      {
25
         printf("%d is present at location %d.\n", search, c+1);
26
         count++;
27
      }
28
    }
29
   if (count == 0)
30
      printf("%d is not present in the array.\n", search);
31
   else
32
      printf("%d is present %d times in the array.\n", search, count);
33
34
   return 0;
35
}
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
4
5
6
5
7
5
5 is present at location 1.\n
5 is present at location 3.\n
5 is present 2 times in the array.
5 is present at location 1.\n
5 is present at location 3.\n
5 is present 2 times in the array.\n
Passed after ignoring Presentation Error
Test Case 2
5
67
80
45
97
100
50
50 is not present in the array.
50 is not present in the array.\n
Passed after ignoring Presentation Error





Week-09 Program-02

Due on 2024-09-26, 23:59 IST
Write a C program to search a given element from a 1D array and display the position at which it is found by using linear search function. The index location starts from 1.
Select the Language for this assignment. 
1
#include <stdio.h>
2
int linear_search(int[], int, int);
3
int main()
4
{
5
   int array[100], search, c, n, position;
6
   /* search - element to search, c - counter, n - number of elements in array,
7
   position - The position in which the element is first found in the list. */
8
9
    scanf("%d", &n); // Number of elements in the array is read from the test case data
10
11
    for (c = 0; c < n; c++)
12
    scanf("%d", &array[c]); //Elements of array is read from the test data
13
14
    scanf("%d", &search);  //Element to search is read from the test case data
15
16
   /* Use the following in the printf statement to print the output
17
   printf("%d is not present in the array.\n", search);
18
   printf("%d is present at location %d.\n", search, position+1); //As array[0] has the position 1
19
   */
20
position = linear_search(array, n, search);
21
22
   if (position == -1)
23
      printf("%d is not present in the array.", search);
24
   else
25
      printf("%d is present at location %d.", search, position+1);
26
   return 0;
27
}
28
29
int linear_search(int a[], int n, int find) {
30
   int c;
31
   for (c = 0 ;c < n ; c++ )
32
    {
33
      if (a[c] == find)
34
         return c;
35
    }
36
   return -1;
37
}
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
78
90
34
54
98
90
90 is present at location 2.
90 is present at location 2.
Passed
Test Case 2
6
30
40
50
20
90
60
90
90 is present at location 5.
90 is present at location 5.
Passed





Week-09 Program-03

Due on 2024-09-26, 23:59 IST
Write a C program to search a given number from a sorted 1D array and display the position at which it is found using binary search algorithm. The index location starts from 1.
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
 int c, n, search,
5
 array[100];
6
 scanf("%d",&n); //number of elements in the array
7
8
 for (c = 0; c < n; c++)
9
 scanf("%d",&array[c]);
10
11
 scanf("%d", &search); //The element to search is read from test case.
12
13
/* Use the printf statements as below:
14
 printf("%d found at location %d.\n", search, variable_name);
15
 printf("Not found! %d isn't present in the list.\n", search);
16
*/
17
int first, last, middle;
18
   first = 0;
19
   last = n - 1;
20
   middle = (first+last)/2;
21
22
   while (first <= last) {
23
      if (array[middle] < search)
24
         first = middle + 1;
25
      else if (array[middle] == search) {
26
         printf("%d found at location %d.", search, middle+1);
27
         break;
28
      }
29
      else
30
         last = middle - 1;
31
32
      middle = (first + last)/2;
33
      }
34
   if (first > last)
35
      printf("Not found! %d isn't present in the list.", search);
36
37
     return 0;
38
      }
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
20
30
40
50
40
40 found at location 4.
40 found at location 4.
Passed
Test Case 2
4
44
55
66
77
10
Not found! 10 isn't present in the list.
Not found! 10 isn't present in the list.
Passed





Week-09 Program-04

Due on 2024-09-26, 23:59 IST
Write a C program to reverse an array by swapping the elements and without using any new array.
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main() {
3
  int array[100], n, c;
4
  scanf("%d", &n); // n is number of elements in the array.
5
  for (c = 0; c < n; c++) {
6
    scanf("%d", &array[c]);
7
  }
8
int temp, end;
9
   end = n - 1;
10
   for (c = 0; c < n/2; c++) {
11
    temp       = array[c];
12
    array[c]   = array[end];
13
    array[end] = temp;
14
15
    end--;
16
  }
0
printf("Reversed array elements are:\n");
1
2
  for (c = 0; c < n; c++) {
3
    printf("%d\n", array[c]);
4
  }
5
  return 0;
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
4
10
20
30
40
Reversed array elements are:\n
40\n
30\n
20\n
10
Reversed array elements are:\n
40\n
30\n
20\n
10\n
Passed after ignoring Presentation Error
Test Case 2
5
50
60
40
30
20
Reversed array elements are:\n
20\n
30\n
40\n
60\n
50
Reversed array elements are:\n
20\n
30\n
40\n
60\n
50\n
Passed after ignoring Presentation Error







Week-10 Program-01

Due on 2024-10-03, 23:59 IST
Write a C code to check if a 3 x 3 matrix is invertible. A matrix is not invertible if its determinant is 0.
Select the Language for this assignment. 
1
#include<stdio.h>
2
 int main()
3
{
4
  int a[3][3], i, j;
5
  long determinant;
6
 //  9 elements of matrix is taken as input from test data
7
  for(i = 0 ; i < 3; i++)
8
      for(j = 0; j < 3; j++)
9
           scanf("%d", &a[i][j]);
10
11
/*Use the printf statements as:
12
printf("The given matrix is not invertible");
13
printf("The given matrix is invertible"); 
14
*/
15
determinant = a[0][0] * ((a[1][1]*a[2][2]) - (a[2][1]*a[1][2])) -a[0][1] * (a[1][0]
16
   * a[2][2] - a[2][0] * a[1][2]) + a[0][2] * (a[1][0] * a[2][1] - a[2][0] * a[1][1]);
17
   if ( determinant == 0)
18
       printf("The given matrix is not invertible");
19
   else
20
       printf("The given matrix is invertible");
21
   return 0;
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
1
2
3
4
5
6
7
8
9
The given matrix is not invertible
The given matrix is not invertible
Passed
Test Case 2
1
0
5
2
1
6
3
4
0
The given matrix is invertible
The given matrix is invertible
Passed





Week-10 Program-02

Due on 2024-10-03, 23:59 IST
Write a C program to sort a 1D array using pointer by applying Bubble sort technique.
Select the Language for this assignment. 
1
#include<stdio.h>
2
void sort(int *a, int n);
3
int main()
4
{
5
    int a[20];
6
    int n,i; 
7
    scanf("%d",&n); // Enter number of elements to sort is taken from test case data
8
   
9
    for(i=0;i<n;i++)
10
    {
11
        scanf("%d",&a[i]); // The elements of the array is taken from the test data
12
    }
13
14
sort(a, n); // Calling the sorting function
15
16
    //Printing the sorted array 
17
    for(i=0;i<n;i++)
18
    {
19
        printf("%d\n",a[i]);
20
    }
21
   return 0;
22
}
23
void sort(int *a, int n)
24
{
25
    int i,temp,j;
26
    for(i=1;i<n;i++)
27
    {
28
        for(j=0;j<n-i;j++)
29
        {
30
           if(*(a+j)>=*(a+j+1))
31
        {
32
            temp = *(a+j);
33
            *(a+j)= *(a+j+1);
34
            *(a+j+1)= temp;
35
        }
36
        }
37
    }
38
}
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
-10
90
30
20
-100
50
-100\n
-10\n
20\n
30\n
50\n
90
-100\n
-10\n
20\n
30\n
50\n
90\n
Passed after ignoring Presentation Error





Week-10 Program-03

Due on 2024-10-03, 23:59 IST
Write a C program to sort a given 1D array using pointer in ascending order.
Your last recorded submission was on 2024-09-27, 09:55 IST
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
    int a[100],i, n;
5
    scanf("%d",&n);  //Number of elements of the array is taken from the test case data 
6
   
7
   for (i=0; i<n; i++)
8
    {
9
        scanf("%d",a+i); // Input the array elements
10
    }
11
int j,t;
12
for (i=0; i<(n-1); i++) 
13
    {
14
        for (j=i+1; j<n; j++)
15
        {
16
            if (*(a+i)>*(a+j))
17
            {
18
                t=*(a+i);
19
                *(a+i)=*(a+j);
20
                *(a+j)=t;
21
            }
22
        }
23
    }
0
//   Printing sorted array in ascending order 
1
    for (i=0; i<n; i++)
2
    {
3
        printf("%d\n",*(a+i));
4
    }
5
    return 0;
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
5
20
40
50
30
10
10\n
20\n
30\n
40\n
50
10\n
20\n
30\n
40\n
50\n
Passed after ignoring Presentation Error





Week-10 Program-04

Due on 2024-10-03, 23:59 IST
Select the Language for this assignment. 
1
#include<stdio.h>
2
float f(float x);
3
float df (float x);
4
5
int main()
6
{
7
    int itr, maxmitr; // itr is the iteration number and maxitr is the maximum allowable iteration 
8
    float x0=1.0, x1; // x0 is the initial value and x1 is result 
9
    scanf("%d", &maxmitr); // Taken from the test cases 
10
11
// use the printf statement as printf("Root = %8.6f\n", x1);
12
float h;
13
    for (itr=1; itr<=maxmitr; itr++)
14
    {
15
        h=f(x0)/df(x0);
16
        x1=x0-h;
17
        x0=x1;
18
    }
19
    printf("Root = %8.6f", x1);
20
    return 0;
21
}
22
float f(float x)
23
{
24
    return x*x*x - 2*x  - 3;
25
}
26
float df (float x)
27
{
28
    return 3*x*x-2;
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
2
Root = 3.465754
Root = 3.465754
Passed
Test Case 2
5
Root = 1.908690
Root = 1.908690
Passed







Week-11 Program-01

Due on 2024-10-10, 23:59 IST
Write a C program to reverse a word using Recursion. Input to the program is a string that is to be taken from the user and output is reverse of the input word. Note that you have to use recursion.
Select the Language for this assignment. 
1
#include <stdio.h>
2
#define MAX 100
3
char *reverse(char[]);
4
5
int main()
6
{
7
    char str[MAX], *rev;
8
    //printf("Enter a String: ");
9
    scanf("%s", str);
10
    rev = reverse(str); //You have to write this function
11
    printf("The reversed string is : %s\n", rev);
12
    return 0;
13
}
14
char* reverse(char str[])
15
{
16
    static int i= 0;
17
    static char rev[MAX];
18
    if (*str)
19
    {
20
        reverse(str+1);
21
        rev[i++]= *str;
22
    }
23
    return rev;
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
KHARAGPUR
The reversed string is : RUPGARAHK
The reversed string is : RUPGARAHK\n
Passed after ignoring Presentation Error







Week-11 Program-02

Due on 2024-10-10, 23:59 IST
Select the Language for this assignment. 
1
#include<stdio.h>
2
int main()
3
{
4
  float t[100]={10,15,18,22,30}, v[100]={22,26,35,48,68};
5
  float a; //Value of the t to find the respective value of v(t)
6
  scanf("%f", &a);  // This will be taken from test cases
7
int i,j;
8
float b, c, k =0;
9
for(i=0; i<5; i++)
10
   {
11
      b=1;
12
      c=1;
13
      for(j=0; j<5; j++)
14
        {
15
           if(j!=i)
16
             {
17
               b=b*(a-t[j]);
18
               c=c*(t[i]-t[j]);
19
              }
20
            }
21
        k=k+((b/c)*v[i]);
22
        }
0
printf("The respective value of the variable v is: %.2f", k);
1
  return 0;
2
}
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
25
The respective value of the variable v is: 56.42
The respective value of the variable v is: 56.42
Passed







Week-11 Program-03

Due on 2024-10-10, 23:59 IST
Select the Language for this assignment. 
1
#include<stdio.h>
2
float func(float x);
3
int main()
4
{
5
  int n=10; //Taking n=10 sub intervals
6
  float a,b,integral; //integral is the integration result
7
  scanf("%f",&a); // initial limit taken from test case 
8
  scanf("%f",&b); // Final limit taken from test case
9
10
//Use the printf statement as printf("The integral is: %0.6f\n",integral);
11
int i;
12
float h,x, sum=0;  
13
if(b>a)
14
  h=(b-a)/n;
15
  else
16
  h=-(b-a)/n;
17
  for(i=1;i<n;i++){
18
    x=a+i*h;
19
    sum=sum+func(x);
20
  }
21
  integral=(h/2)*(func(a)+func(b)+2*sum);
22
  printf("The integral is: %0.6f",integral);
23
  return 0;
24
}
25
float func(float x)
26
{
27
  return x*x;
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
0
1
The integral is: 0.335000
The integral is: 0.335000
Passed






Week-11 Program-04

Due on 2024-10-10, 23:59 IST
Write a C program to check whether the given input number is Prime number or not using recursion. So, the input is an integer and output should print whether the integer is prime or not. Note that you have to use recursion.
Select the Language for this assignment. 
1
#include <stdio.h>
2
int checkPrime(int, int); //Function to check prime or not 
3
4
int main()
5
{
6
    int num, check;
7
    scanf("%d", &num); //The number is taken from test case data
8
    check = checkPrime(num, num/2);
9
    if (check == 1)
10
    {
11
        printf("%d is a prime number\n", num);
12
    }
13
    else
14
    {
15
        printf("%d is not a prime number\n", num);
16
    }
17
    return 0;
18
}
19
int checkPrime(int num, int i)
20
{
21
    if (i == 1)
22
    {
23
        return 1;
24
    }
25
    else
26
    {
27
       if (num % i == 0)
28
       {
29
         return 0;
30
       }
31
       else
32
       {
33
         return checkPrime(num, i - 1);
34
       }
35
    }
36
}
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
13
13 is a prime number
13 is a prime number\n
Passed after ignoring Presentation Error
Test Case 2
40
40 is not a prime number
40 is not a prime number\n
Passed after ignoring Presentation Error






Week-12: Program-01

Due on 2024-10-17, 23:59 IST
Write a program in C to find the factorial of a given number using pointers.
Select the Language for this assignment. 
1
#include <stdio.h>
2
void findFact(int, long int*);
3
int main()
4
{
5
        long int fact; //factorial of the number
6
        int num1; 
7
        scanf("%d",&num1); //The number is taken from test data
8
9
         findFact(num1, &fact);
10
         printf("The Factorial of %d is: %ld\n",num1, fact);
11
         return 0;
12
        }
13
void findFact(int n, long int *f)
14
        {
15
        int i;
16
17
       *f =1;
18
       for(i=1;i<=n;i++)
19
       *f=*f*i;
20
       }
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\n
Passed after ignoring Presentation Error
Test Case 2
10
The Factorial of 10 is: 3628800
The Factorial of 10 is: 3628800\n
Passed after ignoring Presentation Error






Week-12: Program-02

Due on 2024-10-17, 23:59 IST
Write a C program to print the Record of the Student Merit wise. Here a structure variable is defined which contains student rollno, name and score.
Select the Language for this assignment. 
1
#include<stdio.h>
2
struct student
3
{
4
int rollno;
5
char name[20];
6
int score;
7
};
8
void main()
9
{
10
struct student s[20];
11
int i, n;
12
13
scanf("%d" ,&n); //No. of Students taken from test data
14
// Roll no., Name and Score of n students are taken from test data
15
for(i=0;i<n;i++)
16
{
17
scanf("%d", &s[i].rollno);
18
scanf("%s", s[i].name);
19
scanf("%d", &s[i].score);
20
}
21
//Complete the program so that merit list is printed in descending order
22
struct student temp;
23
int j;
24
for(i=0;i<n-1;i++)
25
{
26
for(j=0;j<n-1;j++)
27
{
28
if(s[j].score<s[j+1].score)
29
{
30
temp=s[j];
31
s[j]=s[j+1];
32
s[j+1]=temp;
33
}
34
}
35
}
0
printf("The Merit List is :\n");
1
for(i=0;i<n;i++)
2
{
3
printf("%d", s[i].rollno);
4
printf("  %s", s[i].name);
5
printf("  %d\n", s[i].score);
6
}
7
8
}
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
Santanu
700
2
Aparna
550
3
Vivek
900
The Merit List is :\n
3  Vivek  900\n
1  Santanu  700\n
2  Aparna  550
The Merit List is :\n
3  Vivek  900\n
1  Santanu  700\n
2  Aparna  550\n
Passed after ignoring Presentation Error





Week-12: Program-03

Due on 2024-10-17, 23:59 IST
Write a C program to store n elements using Dynamic Memory Allocation - calloc() and find the Largest element.
Select the Language for this assignment. 
1
#include <stdio.h>
2
#include <stdlib.h>
3
4
int main()
5
{
6
    int n; 
7
    float *element;
8
9
    scanf("%d", &n); //Total number of elements
10
11
    // Allocate the memory for 'n' number of elements. 
12
    //Then take the elements as input from test data
13
element = (float*) calloc(n, sizeof(float));
14
15
    if(element == NULL)
16
    {
17
        printf("Error!!! memory not allocated.");
18
        exit(0);
19
    }
20
21
    // Stores the number entered by the user.
22
    int i;
23
    for(i = 0; i < n; ++i)
24
    {
25
        scanf("%f", element + i);
26
    }
27
28
 // find the largest
29
    for(i = 1; i < n; ++i)
30
    {
31
       if(*element < *(element + i))
32
         *element = *(element + i);
33
    }
34
35
    printf("Largest element = %.2f", *element);
36
37
    return 0;
38
}
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
200
300
500
100
400
Largest element = 500.00
Largest element = 500.00
Passed






Week-12: Program-04

Due on 2024-10-17, 23:59 IST
Write a C program to add two distance given as input in feet and inches.
Select the Language for this assignment. 
1
#include<stdio.h>
2
3
struct Distance{
4
    int feet;
5
    int inch;
6
}d1,d2,sum;
7
8
int main()
9
    {
10
    //Enter 1st distance
11
    scanf("%d",&d1.feet); 
12
    scanf("%d",&d1.inch);
13
    //Enter 2nd distance
14
    scanf("%d",&d2.feet);
15
    scanf("%d",&d2.inch);
16
sum.feet=d1.feet+d2.feet;
17
    sum.inch=d1.inch+d2.inch;
18
 
19
/* If inch is greater than 12, converting it to feet. */
20
    if (sum.inch>=12)
21
    {
22
        sum.inch=sum.inch-12;
23
        ++sum.feet;
24
    }
0
printf("Sum of distances = %d feet %d inches",sum.feet,sum.inch);
1
    return 0;
2
}
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
40
11
10
11
Sum of distances = 51 feet 10 inches
Sum of distances = 51 feet 10 inches
Passed
Test Case 2
10
5
20
5
Sum of distances = 30 feet 10 inches
Sum of distances = 30 feet 10 inches
Passed







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.