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

Posted on August 08, 2023



 Problem Solving Through Programming In C


Subscribe to our YouTube Channel :  Swayam Solver

  Please scroll down for latest Programs. 👇 



Week 3 : Programming Assignment 1

Due on 2023-08-17, 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 2023-08-08, 21:27 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
area = PI * radius * radius;
0
printf("Area of a circle = %5.2f", area);
1
}
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





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



Week 3 : Programming Assignment 2

Due on 2023-08-17, 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 2023-08-08, 21:30 IST
Select the Language for this assignment. 
1
#include <stdio.h>
2
int main()
3
{
4
    double number;
5
    scanf("%lf", &number); 
6
​
7
    /* The number is entered automatically from the test cases and executed */
8
    /* Write the rest of the code in the box below
9
    As the output should exactly match with the output mentioned in the test cases
10
    so copy and paste the following printf statements wherever and whichever is applicable
11
      printf("The number is 0.");
12
      printf("Negative number.");
13
      printf("Positive number.");  
14
    Do not use any other scanf statements */
15
    if (number <= 0.0)
16
    {
17
        if (number == 0.0)
18
            printf("The number is 0.");
19
        else
20
            printf("Negative number.");
21
    }
22
    else
23
        printf("Positive number.");
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
14.05
Positive number.
Positive number.
Passed
Test Case 2
-50
Negative number.
Negative number.
Passed




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



Week 3 : Programming Assignment 3

Due on 2023-08-17, 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 2023-08-08, 21:32 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
   if(number % 2 == 0)
16
        printf("%d is even.", number);
17
    else
18
        printf("%d is odd.", number);
19
}
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
24
24 is even.
24 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 3 : Programming Assignment 4

Due on 2023-08-17, 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 2023-08-08, 21:35 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
    if( n1>=n2 && n1>=n3 )
13
        printf("%d is the largest number.", n1);
14
​
15
    if( n2>=n1 && n2>=n3 )
16
        printf("%d is the largest number.", n2);
17
​
18
    if( n3>=n1 && n3>=n2 )
19
        printf("%d is the largest number.", n3);
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
45 34 67
67 is the largest number.
67 is the largest number.
Passed
Test Case 2
80 -5 3
80 is the largest number.
80 is the largest number.
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed



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



Week 4 : Programming Assignment 1

Due on 2023-08-24, 23:59 IST
Write a C Program to Find the Smallest Number among Three Numbers (integer values) using Nested IF-Else statement.
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
80 40 90
40 is the smallest number.
40 is the smallest number.
Passed
Test Case 2
77 88 -99
-99 is the smallest number.
-99 is the smallest number.
Passed




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


Week 4 : Programming Assignment 2

Due on 2023-08-24, 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).
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
9 9 9
Equilateral Triangle
Equilateral Triangle
Passed
Test Case 2
5 12 13
Right-angle Triangle
Right-angle Triangle
Passed




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



Week 4 : Programming Assignment 3

Due on 2023-08-24, 23:59 IST
Write a program to find the factorial of a given number using while loop.
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




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


Week 4 : Programming Assignment 4

Due on 2023-08-24, 23:59 IST
Write a Program to find the sum of all even numbers from 1 to N where the value of N is taken as input. [For example when N is 10 then the sum is 2+4+6+8+10 = 30]
Select the Language for this assignment. 
1
#include <stdio.h>  
2
void main()
3
{
4
int N, sum=0; 
5
scanf("%d", &N); /* The value of N is taken from the test cases */
6
​
7
/* Complete the program. Please use the printf statement given below to 
8
exactly match your output with the test cases.
9
​
10
printf("Sum = %d", sum);
11
​
12
*/
13
for(int i=2; i <= N; i=i+2)
14
  sum+=i;
15
printf("Sum = %d", sum);
16
}
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
Sum = 30
Sum = 30
Passed
Test Case 2
15
Sum = 56
Sum = 56
Passed




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


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


Week 5 : Programming Assignment 1

Due on 2023-08-31, 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
Copy and paste the printf statement given below wherever required to avoid errors.
9
printf("\n%d is a perfect number.",N);
10
printf("\n%d is not a perfect number.",N);
11
*/
12
int i,sum=0;
13
for(i=1;i<N;i++)
14
  if(N%i==0)
15
   sum+=i;
16
​
17
if(sum==N)
18
  printf("%d is a perfect number.",N);
19
else
20
  printf("%d is not a perfect number.",N);
21
​
22
return 0;
23
​
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 5 : Programming Assignment 2

Due on 2023-08-31, 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
}
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
3008
The number 3008 contains 4 digits.
The number 3008 contains 4 digits.
Passed
Test Case 2
123456
The number 123456 contains 6 digits.
The number 123456 contains 6 digits.
Passed


Week 5 : Programming Assignment 3

Due on 2023-08-31, 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
66
66 cannot be expressed as power of 2.
66 cannot be expressed as power of 2.
Passed


Week 5 : Programming Assignment 4

Due on 2023-08-31, 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

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
int i;
14
for(i=1;i<=N;i++)
15
sum = sum + ((float)1/(float)i);
16
printf("Sum of the series is: %.2f", sum);
17
}
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
Sum of the series is: 2.45
Sum of the series is: 2.45
Passed
Test Case 2
50
Sum of the series is: 4.50
Sum of the series is: 4.50
Passed




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




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. 
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 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. 
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
int j, temp;  
11
j = i - 1;   // last Element of the array
12
i = 0;       // first element of the array
13
 
14
   while (i < j) {
15
      temp = arr[i];
16
      arr[i] = arr[j];
17
      arr[j] = temp;
18
      i++;             
19
      j--;        
20
   }
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 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. 
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
19
int j;
20
for (i=0;i<n1;++i)
21
array_new[i]=arr1[i];
22
​
23
size =  n1 + n2;
24
​
25
for(i=0, j=n1; j<size && i<n2; ++i, ++j)
26
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
}
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. 
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




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




Week 7 : Programming Assignment 1

Due on 2023-09-14, 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 7 : Programming Assignment 2

Due on 2023-09-14, 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 7 : Programming Assignment 3

Due on 2023-09-14, 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 7 : Programming Assignment 4

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

Your last recorded submission was on 2023-09-02, 21:29 IST
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
int i=0,j=0,k=0,a,minIndex=0,maxIndex=0,max=0,min=0;
17
char c; 
18
while(str[k]!='\0')  //for splitting sentence into words 
19
    {
20
        j=0;
21
        while(str[k]!=' '&&str[k]!='\0' && str[k]!='.')
22
        {
23
            substr[i][j]=str[k];
24
            k++;
25
            j++;
26
        }
27
        substr[i][j]='\0';
28
        i++;
29
        if(str[k]!='\0')
30
        {
31
            k++;
32
        }        
33
    }
34
    int len=i;
35
    max=strlen(substr[0]);
36
    min=strlen(substr[0]);
37
​
38
    //After splitting getting length of string and finding its index having max length and index having min length
39
    for(i=0;i<len;i++)
40
    {
41
       a=strlen(substr[i]);
42
       if(a>max)
43
        {
44
            max=a;
45
            maxIndex=i;
46
        }
47
        if(a<min)
48
        {
49
            min=a;
50
            minIndex=i;
51
        }
52
    }    
53
  printf("Largest Word is: %s\nSmallest word is: %s\n",substr[maxIndex],substr[minIndex]);
54
  return 0;  
55
}
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
Largest Word is: Programming\n
Smallest word is: C\n
Passed after ignoring Presentation Error
Test Case 2
NPTEL is a joint initiative of the IITs and IISc.
Largest Word is: initiative\n
Smallest word is: a
Largest Word is: initiative\n
Smallest word is: a\n
Passed after ignoring Presentation Error



Week 8 : Programming Assignment 1

Due on 2023-09-21, 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 8 : Programming Assignment 2

Due on 2023-09-21, 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 8 : Programming Assignment 3

Due on 2023-09-21, 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 8 : Programming Assignment 4

Due on 2023-09-21, 23:59 IST
Write a C Program to reverse a given word using function. e.g. INDIA should be printed as AIDNI
Your last recorded submission was on 2023-09-10, 22:21 IST
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



























 

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

Quick Links

  • Home
  • About
  • Contact
  • Privacy Policy

Follow us on

YouTube WhatsApp Telegram

Designed by Swayam Solver © 2024