NPTEL Problem Solving Through Programming In C - Programming Assignment Week-6 | Sept-2023 Swayam

 

Week 6 : Programming Assignment 1

Due on 2023-09-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. 
#include <stdio.h>
 
int main()
{
    int i, n, largest;
    int arr[100];
 
    scanf("%d", &n); /*Accepts total number of elements from the test data */
 
 for(i = 0; i < n; ++i)
    {
       scanf("%d", &arr[i]); /* Accepts the array element from test data */
    }
largest = arr[0];
for(i = 1; i< n; ++i)
    {
if(largest <arr[i])
           largest = arr[i];
    }
printf("Largest element = %d", largest);
 
    return 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
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 : Programming Assignment 2

Due on 2023-09-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.

Your last recorded submission was on 2023-08-26, 22:18 IST
Select the Language for this assignment. 
#include<stdio.h>
 
int main() {
   int arr[20], i, n;
 
   scanf("%d", &n); /* Accepts the number of elements in the array */
 
  for (i = 0; i < n; i++) 
     scanf("%d", &arr[i]); /*Accepts the elements of the array */
int j, temp;  
j = i - 1;   // last Element of the array
i = 0;       // first element of the array
 
   while (i < j) {
      temp = arr[i];
      arr[i] = arr[j];
      arr[j] = temp;
      i++;             
      j--;        
   }
for (i = 0; i < n; i++) {
      printf("%d\n", arr[i]); // For printing the array elements 
   }
 
   return (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
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 : Programming Assignment 3

Due on 2023-09-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. 
#include<stdio.h>
int main() 
{
   int arr1[20], arr2[20], array_new[40], n1, n2, size, i;
 /*n1 size of first array (i.e. arr1[]), n2 size of second array(i.e. arr2[]), 
   size is the total size of the new array (array_new[]) */
 
   scanf("%d", &n1); //Get the size of first array from test data and store it in n1.
   
   for (i = 0; i < n1; i++)
      scanf("%d", &arr1[i]); //Accepts the values for first array 
 
   scanf("%d", &n2); //Get the size of second array from test data and store it in n2.
   
   for (i = 0; i < n2; i++)
      scanf("%d", &arr2[i]); //Accepts the values for second array
 
//Marge two arrays
int j;
for (i=0;i<n1;++i)
array_new[i]=arr1[i];
 
size =  n1 + n2;
 
for(i=0, j=n1; j<size && i<n2; ++i, ++j)
array_new[j] = arr2[i];
//Printing after merging
 
for (i = 0; i < size; i++) {
      printf("%d\n", array_new[i]);
   }
 
}
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 : Programming Assignment 4

Due on 2023-09-07, 23:59 IST
Write a C Program to delete duplicate elements from an array of integers.
Select the Language for this assignment. 
#include<stdio.h>
 
int main() 
{
   int array[50], i, size;
 
   scanf("%d", &size); /*Accepts the size of array from test case data */
 
   for (i = 0; i < size; i++)
   scanf("%d", &array[i]); /* Read the array elements from the test case data */
int j, k;
   for (i = 0; i< size; i++) {
      for (j = i + 1; j < size;) {
         if (array[j] == array[i]) {
            for (k = j; k < size; k++) {
               array[k] = array[k + 1];
            }
            size--;
         } else
j++;
      }
   }
for (i = 0; i < size; i++) {
      printf("%d\n", array[i]);
   }
 
}
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




.......................................................................................................................................


No comments

JavaFX Scene Builder

  This is an article about the JavaFX Scene Builder. You will get a short introduction about the installation and usage of the software. The...