Problem Solving Through Programming in C Week 6: Programming Assignments Jan-Jun 2022

  NPTEL PROGRAMMING ASSIGNMENTS


Problem Solving Through Programming in C

Week-06 Program-01

Due Date of Submission 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);


#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 */
    }


 

 



 

Week-06 Program-02

Due Date of Submission 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.


#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 */

 

 

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





Week-06 Program-03

Due Date of Submission 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.


#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[]) */
   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]);

 

 

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




Week-06 Program-04

Due Date of Submission 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.



#include<stdio.h>
int main() {
int array[30], num, i, pos;
scanf("%d", &num);
   for (i = 0; i<num; i++) {
scanf("%d", &array[i]);
   }
scanf("%d", &pos);

 

 

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

Post a Comment (0)
Previous Post Next Post