Home

Swayam Solver

Learn Programming & Prepare for NPTEL Exams...

Find your course

Explore Courses

Latest Blog Posts

NPTEL Problem Solving Through Programming In C - Programming Assignment | July-2024 Week 4 to 8

NPTEL Problem Solving Through Programming In C - Programming Assignment | July-2024 Week 4 to 8



Week-04: Program-01

Due on 2024-08-22, 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 2024-08-14, 18:29 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
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
20 30 10
10 is the smallest number.
10 is the smallest number.
Passed
Test Case 2
77 -44 99
-44 is the smallest number.
-44 is the smallest number.
Passed




Week-04: Program-02

Due on 2024-08-22, 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).
Your last recorded submission was on 2024-08-14, 18:31 IST
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
10 4 6
Triangle is not possible
Triangle is not possible
Passed
Test Case 2
7 6 8
Scalene Triangle
Scalene Triangle
Passed
Test Case 3
9 9 9
Equilateral Triangle
Equilateral Triangle
Passed





Week-04 Program-03

Due on 2024-08-22, 23:59 IST
Write a program to find the factorial of a given number using while loop.
Your last recorded submission was on 2024-08-14, 18:32 IST
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




Week-04: Program-04

Due on 2024-08-22, 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 2024-08-14, 18:33 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
if(exponent == 0) 
9
   result = 1;
10
else
11
{
12
result = 1;
13
while(exponent != 0)
14
{
15
result = result * base;
16
--exponent;
17
}
18
}
0
printf("The result is : %ld\n", result);
1
return 0;
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
5
4
The result is : 625
The result is : 625\n
Passed after ignoring Presentation Error
Test Case 2
7
3
The result is : 343
The result is : 343\n
Passed after ignoring Presentation Error