Home

Learn Programming & Prepare for NPTEL Exams... Swayam Solver is your one-stop destination for NPTEL exam preparation.

Problem Solving Through Programming In C | Week-04: Programs | Jan-2022 | NPTEL

  Problem Solving Through Programming In C 




Week-04: Program-01

Due on 2022-02-24, 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-02-19, 07:42 IST
Select the Language for this assignment. 
Just scroll your mouse wheel over this code or swipe on this code snippet to scroll down to see the remaining code.
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)
16
    {
17
        if(n1<n3)
18
            printf("%d is the smallest number.", n1);
19
        else
20
            printf("%d is the smallest number.", n3);
21
    }
22
    else
23
    {
24
        if(n2<n3)
25
            printf("%d is the smallest number.", n2);
26
        else
27
            printf("%d is the smallest number.", n3);
28
    }
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
100 200 400
100 is the smallest number.
100 is the smallest number.
Passed
Test Case 2
90 -9 8
-9 is the smallest number.
-9 is the smallest number.
Passed


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







Week-04: Program-02

Due on 2022-02-24, 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-02-19, 07:44 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
result=1;
10
while(exponent-- > 0)
11
  result*=base;
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
4
8
The result is : 65536\n
The result is : 65536\n
Passed
Test Case 2
5
4
The result is : 625\n
The result is : 625\n
Passed


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









Week-04 Program-03

Due on 2022-02-24, 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-02-19, 07:47 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;
10
First_digit = N;
11
12
while(First_digit >=10)
13
{
14
    First_digit = First_digit/10;
15
}
16
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
5670
Sum of First and Last digit = 5
Sum of First and Last digit = 5
Passed

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









Week-04 Program-04

Due on 2022-02-24, 23:59 IST
Write a program to find the factorial of a given number using while loop.
Your last recorded submission was on 2022-02-19, 07:49 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
15
int i=1;
16
fact = 1;
17
while(i<=n)
18
    {
19
        fact*=i;
20
        i++;
21
    }
22
    printf("The Factorial of %d is : %ld",n,fact);
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
7
The Factorial of 7 is : 5040
The Factorial of 7 is : 5040
Passed
Test Case 2
11
The Factorial of 11 is : 39916800
The Factorial of 11 is : 39916800
Passed

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







Please subscribe to our YouTube Channel :  Swayam Solver

This will help the creator to continue making qualilty content...

Have a great day !

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.