Problem Solving Through Programming In C | Week-06: Programs | Jan-2022 | NPTEL

 


Week-06 Program-01

Due on 2022-03-10, 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
15
largest=arr[0];
 for(i = 0; i < n; ++i)
    {
       if(largest>arr[i])
         continue;
       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





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




Week-06 Program-02

Due on 2022-03-09, 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
11
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--;        
   }
0
for (i = 0; i< n; i++) {
1
printf("%d\n", arr[i]); // For printing the array elements 
2
   }
3
4
   return (0);
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
5
1
2
3
4
5
5\n
4\n
3\n
2\n
1\n
5\n
4\n
3\n
2\n
1\n
Passed
Test Case 2
4
45
65
35
25
25\n
35\n
65\n
45\n
25\n
35\n
65\n
45\n
Passed




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





Week-06 Program-03

Due on 2022-03-10, 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
18
//Merge 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];
0
//Printing after merging
1
2
for (i = 0; i< size; i++) {
3
printf("%d\n", array_new[i]);
4
   }
5
6
}
7
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\n
10\n
20\n
30\n
40\n
50\n
60\n
70\n
Passed
Test Case 2
4
9
7
6
5
2
30
50
9\n
7\n
6\n
5\n
30\n
50\n
9\n
7\n
6\n
5\n
30\n
50\n
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed





Week-06 Program-04

Due on 2022-03-10, 23:59 IST
C Program to delete an element from a specified location of an Array starting from array[0] as the 1st position, array[1] as second position and so on.
Select the Language for this assignment. 
1
#include<stdio.h>
2
int main() {
3
int array[30], num, i, pos;  
4
/*num is number of elements in the array and loc is the position of the array to be deleted. 
5
starting from arr[0] as the first(1) position and so on. */
6
7
scanf("%d", &num); /*Accepts the size of array from test case data */
8
9
   for (i = 0; i<num; i++) {
10
scanf("%d", &array[i]);  /* Read the array elements from the test case data */
11
   }
12
13
scanf("%d", &pos); /* Accepts the Position of the element to be deleted */
14
15
/* loop for the deletion  */
   while (pos < num) {
      array[pos - 1] = array[pos];
      pos++;
   }
   num--; /* No of elements reduced by 1 as 1 element is deleted */
0
/* Printing the array after deletion */
1
2
for (i = 0; i<num; i++)
3
printf("%d\n", array[i]);
4
5
   return (0);
6
}
7
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
4
10\n
20\n
30\n
50\n
10\n
20\n
30\n
50\n
Passed
Test Case 2
6
600
500
400
300
300
200
4
600\n
500\n
400\n
300\n
200\n
600\n
500\n
400\n
300\n
200\n
Passed




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

No comments

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...