NPTEL Problem Solving Through Programming In C - Programming Assignment Week-4 | August-2023 Swayam

 

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. 
#include <stdio.h>
int main()
{
    int n1, n2, n3; 
    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 */
 
/* Complete the program to get the desired output */
/* Only use the printf statement given below to exactly match your output 
with the output cases. Change the variable n1 as required.
 
printf("%d is the smallest number.", n1);    //Copy and paste this printf statement wherever required. 
 
*/
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
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. 
#include<stdio.h>
int main()
{
    int a,b,c; 
    scanf("%d %d %d",&a, &b, &c); /*The length of three sides are entered from the test cases */
 
/* Complete the program. Copy and paste from the printf statements mentioned below wherever required for printing the outputs 
 
printf("Triangle is not possible");
printf("Right-angle Triangle");
printf("Isosceles Triangle");
printf("Equilateral Triangle");
printf("Scalene Triangle");
 
*/
if(a<(b+c)&&b<(a+c)&&c<(a+b))
{
    if(a==b&&a==c&&b==c)
        printf("Equilateral Triangle");
    else if(a==b||a==c||b==c)
        printf("Isosceles Triangle") ;
    else if((a*a)==(b*b)+(c*c)||(b*b)==(a*a)+(c*c)||(c*c)==(a*a)+(b*b))
        printf("Right-angle Triangle");
    else if((a!=b)&&(a!=c)&&(b!=c))
        printf("Scalene Triangle");
    }
else
    printf("Triangle is not possible");
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
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. 
#include<stdio.h>
void main()
{
    int n;
    long int fact;  /* n is the number whose factorial we have to find and fact is the factorial */
    scanf("%d",&n);  /* The value of n is taken from test cases */
 
/* complete the program. Use the printf statements in the format mentioned below 
to match your output exactly with output test cases 
 
printf("The Factorial of %d is : %ld",n,fact);
 
You can declare any other variables if required */
fact = 1;
for(int i=n;i>0;i--)
  fact*=i;
printf("The Factorial of %d is : %ld",n,fact);
}
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. 
#include <stdio.h>  
void main()
{
int N, sum=0; 
scanf("%d", &N); /* The value of N is taken from the test cases */
 
/* Complete the program. Please use the printf statement given below to 
exactly match your output with the test cases.
 
printf("Sum = %d", sum);
 
*/
for(int i=2; i <= N; i=i+2)
  sum+=i;
printf("Sum = %d", 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
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


No comments

JavaFX Scene Builder

  This is an article about the JavaFX Scene Builder. You will get a short introduction about the installation and usage of the software. The...