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-05: Programs | Jan-2022 | NPTEL

 Problem Solving Through Programming In C 



Week-05 Problem-01

Due on 2022-03-03, 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-02-24, 07:32 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 count=0,n;
n=N;
while(n!=0)
{
  count=count+1;
  n=n/10;
  
}
printf("The number %d contains %d digits.",N,count);
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
789
The number 789 contains 3 digits.
The number 789 contains 3 digits.
Passed
Test Case 2
300890
The number 300890 contains 6 digits.
The number 300890 contains 6 digits.
Passed



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







Week-05 Problem-02

Due on 2022-03-03, 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-02-24, 07:32 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
6
Sum of the series is: 2.45\n
Sum of the series is: 2.45\n
Passed
Test Case 2
100
Sum of the series is: 5.19\n
Sum of the series is: 5.19\n
Passed




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









Week-05 Program-03

Due on 2022-03-03, 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-02-24, 07:34 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
3
***\n
**\n
*\n
***\n
**\n
*\n
Passed



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









Week-05 Program-04

Due on 2022-03-03, 23:59 IST
Your last recorded submission was on 2022-02-27, 12:02 IST
Select the Language for this assignment. 
1
#include<stdio.h>
2
int main()
3
{
4
int n, sum=0;
5
scanf("%d",&n); //Value of n is taken from the test cases 
6

int i;
for(i=1;i<=n; i=i+2)
  {
    sum+=i*i;
  }
    printf("Sum = %d",sum);
    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
15
Sum = 680
Sum = 680
Passed
Test Case 2
9
Sum = 165
Sum = 165
Passed



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

Watch the video to see the program in motion.


Please subscribe to our YouTube Channel :  Swayam Solver

This will help the creator to continue making quality 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.