Home
  • C
  • C++
  • Java
  • Python
  • All Courses
  • About us
  • Home
  • C
  • C++
  • Java
  • Python
  • All Courses
  • About us
  • Contact
  • Privacy Policy

Swayam Solver

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-2022 Swayam

Posted on August 13, 2022

 

 Problem Solving Through Programming In C


Subscribe to our YouTube Channel :  Swayam Solver

  Please scroll down for latest Programs. 👇 


Week-03: Program-01

Due on 2022-08-18, 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.
[Marks for Week 3 Programming assignments will not be evaluated finally. This is for users to get familiar with programming in google course builder platform]
Your last recorded submission was on 2022-08-13, 08:43 IST
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
 
21
area = PI * radius * radius;
0
printf("Area of a circle = %5.2f", area);
1
}
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
42
Area of a circle = 5538.96
Area of a circle = 5538.96
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





Week-03: Program-02

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

[Week 3 programming assignments will not be considered for final evaluation]
Your last recorded submission was on 2022-08-13, 08:43 IST
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
 
15
if (number <= 0.0)
    {
        if (number == 0.0)
            printf("The number is 0.");
        else
            printf("Negative number.");
    }
    else
        printf("Positive number.");
}
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
-0.9
Negative number.
Negative number.
Passed



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




Week-03: Program-03

Due on 2022-08-18, 23:59 IST
Write a C program to check whether a given number (integer) is Even or Odd.
[This program does not carry any marks.]
Your last recorded submission was on 2022-08-13, 08:44 IST
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
    int number;
5
    scanf("%d", &number); /*An integer number is taken from the test case */
6
 
7
/* Write the rest of the program in the box provided below. As the output
8
should exactly match with the output provided in the test cases so use exactly the 
9
following printf statement wherever and whichever is applicable. 
10
 
11
printf("%d is even.", number);
12
printf("%d is odd.", number);
13
 
14
*/
15
 
16
if(number % 2 == 0)
        printf("%d is even.", number);
    else
        printf("%d is odd.", number);
}
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
116
116 is even.
116 is even.
Passed
Test Case 2
51
51 is odd.
51 is odd.
Passed



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





Week-03 Program-04

Due on 2022-08-18, 23:59 IST
Write a C Program to find the Largest Number (integer) among Three Numbers (integers) using IF and Logical && operator.
[Week 3 programming assignments will not be considered for final evaluation]
Your last recorded submission was on 2022-08-13, 08:44 IST
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
    int n1, n2, n3;
5
 
6
    scanf("%d %d %d", &n1, &n2, &n3); /*Three numbers are accepted from the test case */
7
 
8
/*  Complete the code in the box provided below. Use printf statement as provided below:
9
printf("%d is the largest number.", n1);
10
It may be n1, n2 or n3.
11
*/
12
 
13
if( n1>=n2 && n1>=n3 )
        printf("%d is the largest number.", n1);
    if( n2>=n1 && n2>=n3 )
        printf("%d is the largest number.", n2);
    if( n3>=n1 && n3>=n2 )
        printf("%d is the largest number.", n3);
}
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
45 34 67
67 is the largest number.
67 is the largest number.
Passed
Test Case 2
-9 -4 -20
-4 is the largest number.
-4 is the largest number.
Passed



Private Test cases used for EvaluationStatus
Test Case 1
Passed



------------------------------------------------------------------------



Week-04: Program-01

Due on 2022-08-25, 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 2022-08-22, 09:08 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
 
15
if (n1<n2)
    {
        if(n1<n3)
            printf("%d is the smallest number.", n1);
        else
            printf("%d is the smallest number.", n3);
    }
    else
    {
        if(n2<n3)
            printf("%d is the smallest number.", n2);
        else
            printf("%d is the smallest number.", n3);
    }
}

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 100 50
20 is the smallest number.
20 is the smallest number.
Passed
Test Case 2
90 45 -81
-81 is the smallest number.
-81 is the smallest number.
Passed





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



Week-04 Problem-02

Due on 2022-08-25, 23:59 IST
Write a program to find whether a given character is a Vowel or consonant. A character is taken as input. The character may be in Upper Case or in Lower Case.
Your last recorded submission was on 2022-08-22, 09:09 IST
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
    char ch;
5
    scanf("%c",&ch);  /* It reads a character from the input cases and store it in ch */
6
 
7
/* Complete the program. Use the printf statement given below to match your 
8
output exactly with the test cases. 
9
 
10
printf("%c is a vowel.", ch);
11
printf("%c is a consonant.", ch);
12
 
13
*/
14
 
15
switch(ch)
{
  case 'a':
  case 'A':
  case 'e':
  case 'E':
  case 'i':
  case 'I':
  case 'o':
  case 'O':
  case 'u':
  case 'U': printf("%c is a vowel.", ch);
            break;
  default : printf("%c is a consonant.", ch);
    }

}
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
C
C is a consonant.
C is a consonant.
Passed
Test Case 2
U
U is a vowel.
U is a vowel.
Passed



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





Week-04 Problem-03

Due on 2022-08-25, 23:59 IST
Write a C program to calculate the Sum of First and the Last Digit of a given Number.
For example if the number is 1234 the result is 1+ 4 = 5.
Your last recorded submission was on 2022-08-22, 09:09 IST
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
 
5
int N, First_digit, Last_digit;
6
 
7
scanf("%d", &N); //The number is accepted from the test case
8
 
9
Last_digit = N%10;
First_digit = N;

while(First_digit >=10)
{
    First_digit = First_digit/10;
}

0
printf("Sum of First and Last digit = %d", First_digit + Last_digit);
1
 
2
return 0;
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
2908
Sum of First and Last digit = 10
Sum of First and Last digit = 10
Passed
Test Case 2
20008
Sum of First and Last digit = 10
Sum of First and Last digit = 10
Passed



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




Week-04: Program-04

Due on 2022-08-25, 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 2022-08-22, 09:10 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
 
9
if(exponent == 0) 
   result = 1;
else
{
result = 1;
while(exponent != 0)
{
result = result * base;
--exponent;
}
}

0
printf("The result is : %ld\n", result);
1
return 0;
2
}
3
 
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
4
8
The result is : 65536
The result is : 65536\n
Passed after ignoring Presentation Error




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




------------------------------------------------------------------------



Week-05 Problem-01

Due on 2022-09-01, 23:59 IST
Write a C program to count total number of digits of an Integer number (N).
Your last recorded submission was on 2022-08-26, 21:58 IST
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
 
14
int temp, count; 
count=0;
    temp=N;
    while(temp>0)
    {
        count++;
        temp/=10;
    }
printf("The number %d contains %d digits.",N,count);
}
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



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





Week-05 Problem-02

Due on 2022-09-01, 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
Your last recorded submission was on 2022-08-26, 21:59 IST
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
 
14
int i;
for(i=1;i<=N;i++)
sum = sum + ((float)1/(float)i);
printf("Sum of the series is: %.2f\n",sum);
}
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
Sum of the series is: 5.19\n
Sum of the series is: 5.19\n
Passed
Test Case 2
20
Sum of the series is: 3.60\n
Sum of the series is: 3.60\n
Passed



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




Week-05 Problem-03

Due on 2022-09-01, 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.

Your last recorded submission was on 2022-08-26, 21:59 IST
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
 
13
int temp, flag;
    temp=N;
    flag=0;

    while(temp!=1)
    {
        if(temp%2!=0){
            flag=1;
            break;
        }
        temp=temp/2;
    }

    if(flag==0)
        printf("%d is a number that can be expressed as power of 2.",N);
    else
        printf("%d cannot be expressed as power of 2.",N);
}
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
6572
6572 cannot be expressed as power of 2.
6572 cannot be expressed as power of 2.
Passed



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





Week-05 Program-04

Due on 2022-09-01, 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

*****
****
***
**
*

Your last recorded submission was on 2022-08-26, 22:00 IST
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
 
7
int i, j;
for(i=N; i>0; i--)
  {
  for(j=0;j<i;j++)
    {
printf("*");
    }
printf("\n");
  } 
}
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
*\n
Passed
Test Case 2
4
****\n
***\n
**\n
*\n
****\n
***\n
**\n
*\n
Passed




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



------------------------------------------------------------------------



Week-06 Program-01

Due on 2022-09-08, 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);

Your last recorded submission was on 2022-08-30, 11:11 IST
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 = 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



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





Week-06 Program-02

Due on 2022-09-08, 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 2022-08-30, 11:11 IST
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-09-08, 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.
Your last recorded submission was on 2022-08-30, 11:12 IST
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
//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];
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
Test Case 2
Passed





Week-06 Program-04

Due on 2022-09-08, 23:59 IST
Write a C Program to delete duplicate elements from an array of integers.
Your last recorded submission was on 2022-08-30, 11:13 IST
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
 
12
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++;
      }
   }
0
for (i = 0; i< size; i++) {
1
printf("%d\n", array[i]);
2
   }
3
 
4
}
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
50
60
30
20
30
50\n
60\n
30\n
20\n
50\n
60\n
30\n
20\n
Passed
Test Case 2
6
40
20
50
30
20
10
40\n
20\n
50\n
30\n
10\n
40\n
20\n
50\n
30\n
10\n
Passed



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







Week-07 Program-01

Due on 2022-09-15, 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
 
21
int sum;
    for(i=0;i< r;i++)
    {
        sum=0;      
        for(j=0;j< c;j++)
        {
          //  printf("%d\t",matrix[i][j]);   
            sum     +=  matrix[i][j];
        }
        printf("%d\n",sum);
    }

}
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\n
3\n
6\n
9\n
Passed
Test Case 2
2
3
1
2
3
4
5
6
6\n
15\n
6\n
15\n
Passed




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







Week-07 Program-02

Due on 2022-09-15, 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
 
33
/* 
    Subtract both matrices and store the result in matrix C
  */
   for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++)
        {

            matrix_C[i][j] = matrix_A[i][j] - matrix_B[i][j];
        }
    }

     for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++)
        {
            printf("%d ", matrix_C[i][j]);
        }
        printf("\n");
    }

    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
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 \n
1 -2 3 \n
2 2 2 \n
3 2 3 \n
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed





Week-07 Program-03

Due on 2022-09-15, 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
 
21
for(i=0; i<r; i++) {
        for(j=0; j<r; j++) {
            if(i>=j)
                printf("%d ", matrix[i][j]);
            else
                printf("%d ", 0);
        }
        printf("\n");
    }
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
3
1
2
3
1
2
3
1
2
3
1 0 0 \n
1 2 0 \n
1 2 3 \n
1 0 0 \n
1 2 0 \n
1 2 3 \n
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed






Week-07 Program-04

Due on 2022-09-15, 23:59 IST
Write a C program to print Largest and Smallest Word from a given sentence. If there are two or more words of same length, then the first one is considered. A single letter in the sentence is also consider as a word.
Select the Language for this assignment. 
1
#include<stdio.h>
2
#include<string.h>
3
int main()
4
{
5
    char str[100]={0},substr[100][100]={0}; 
6
//str[100] is for storing the sentence and substr[50][50] is for storing each word.
7
    
8
scanf("%[^\n]s", str); //Accepts the sentence from the test case data.
9
 
10
/* Complete the program to get the desired output.
11
The print statement should be as below
12
 
13
printf("Largest Word is: %s\nSmallest word is: %s\n", -------,--------);
14
 
15
*/
16
 
17
int i=0,j=0,k=0,a,minIndex=0,maxIndex=0,max=0,min=0;
char c; 
while(str[k]!='\0')  //for splitting sentence into words 
    {
        j=0;
        while(str[k]!=' '&&str[k]!='\0' && str[k]!='.')
        {
            substr[i][j]=str[k];
            k++;
            j++;
        }
        substr[i][j]='\0';
        i++;
        if(str[k]!='\0')
        {
            k++;
        }        
    }
    int len=i;
    max=strlen(substr[0]);
    min=strlen(substr[0]);

    //After splitting getting length of string and finding its index having max length and index having min length
    for(i=0;i<len;i++)
    {
       a=strlen(substr[i]);
       if(a>max)
        {
            max=a;
            maxIndex=i;
        }
        if(a<min)
        {
            min=a;
            minIndex=i;
        }
    }    
  printf("Largest Word is: %s\nSmallest word is: %s\n",substr[maxIndex],substr[minIndex]);
  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
Problem Solving through Programming in C.
Largest Word is: Programming\n
Smallest word is: C\n
Largest Word is: Programming\n
Smallest word is: C\n
Passed
Test Case 2
NPTEL is a joint initiative of the IITs and IISc.
Largest Word is: initiative\n
Smallest word is: a\n
Largest Word is: initiative\n
Smallest word is: a\n
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed






































































































































































































Subscribe to our YouTube Channel :  Swayam Solver

















































































































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.

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Contact Form

Name

Email *

Message *

Total Page views

749,354

Quick Links

  • Home
  • About
  • Contact
  • Privacy Policy

Follow us on

YouTube WhatsApp Telegram

Designed by Swayam Solver © 2024