NPTEL Problem Solving Through Programming In C Week 12 : Programming Assignment 1-5

 

Week 12 : Programming Assignment 1

Due on 2023-10-19, 23:59 IST

Write a program in C to find the factorial of a given number using pointers.

Your last recorded submission was on 2023-10-09, 13:25 IST
Select the Language for this assignment. 
#include <stdio.h>
void findFact(int, long int*);
int main()
{
        long int fact; //factorial of the number
        int num1; 
        scanf("%d",&num1); //The number is taken from test data
 
         findFact(num1, &fact);
         printf("The Factorial of %d is : %ld\n",num1, fact);
         return 0;
        }
void findFact(int n, long int *f)
        {
        int i;
 
       *f =1;
       for(i=1;i<=n;i++)
       *f=*f*i;
       }
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.
   



Private Test cases used for EvaluationStatus
Test Case 1
Passed





Week 12 : Programming Assignment 2

Due on 2023-10-19, 23:59 IST
Write a C program to print the Record of the Student Merit wise. Here a structure variable is defined which contains student rollno, name and score.
Select the Language for this assignment. 
#include<stdio.h>
struct student
{
int rollno;
char name[20];
int score;
};
void main()
{
struct student s[20];
int i, n;
 
scanf("%d" ,&n); //No. of Students taken from test data
// Roll no., Name and Score of n students are taken from test data
for(i=0;i<n;i++)
{
scanf("%d", &s[i].rollno);
scanf("%s", s[i].name);
scanf("%d", &s[i].score);
}
//Complete the program so that merit list is printed in descending order
struct student temp;
int j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1;j++)
{
if(s[j].score<s[j+1].score)
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}
}
printf("The Merit List is :\n");
for(i=0;i<n;i++)
{
printf("%d", s[i].rollno);
printf("  %s", s[i].name);
printf("  %d\n", s[i].score);
}
 
}
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
1
Santanu
700
2
Aparna
550
3
Vivek
900
The Merit List is :\n
3  Vivek  900\n
1  Santanu  700\n
2  Aparna  550
The Merit List is :\n
3  Vivek  900\n
1  Santanu  700\n
2  Aparna  550\n
Passed after ignoring Presentation Error




Week 12 : Programming Assignment 3

Due on 2023-10-19, 23:59 IST
Write a C program to store n elements using Dynamic Memory Allocation - calloc() and find the Largest element
Select the Language for this assignment. 
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int n; 
    float *element;
 
    scanf("%d", &n); //Total number of elements
 
    // Allocate the memory for 'n' number of elements. 
    //Then take the elements as input from test data
element = (float*) calloc(n, sizeof(float));
 
    if(element == NULL)
    {
        printf("Error!!! memory not allocated.");
        exit(0);
    }
 
    // Stores the number entered by the user.
    int i;
    for(i = 0; i < n; ++i)
    {
        scanf("%f", element + i);
    }
 
 // find the largest
    for(i = 1; i < n; ++i)
    {
       if(*element < *(element + i))
         *element = *(element + i);
    }
 
 
    printf("Largest element = %.2f", *element);
 
    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
5
200
300
500
100
400
Largest element = 500.00
Largest element = 500.00
Passed



Week 12 : Programming Assignment 4

Due on 2023-10-19, 23:59 IST

Write a C program to find the sum of two 1D integer arrays ‘A’  and ‘B’ of same size and store the result in another array ‘C’, where the size of the array and the elements of the array are taken as input.
In the Test case the input is given as follows

5

10

20

30

40

50

1

2

3

4

5

So the output will be displayed as

Result is

11

22

33

44

55

Write the program accordingly. Use dynamic memory allocation. 

Select the Language for this assignment. 
#include<stdio.h>
#include<stdlib.h>
 
void main()
{
 int i,n;
 
//The number of elements in each array is taken from test case data 
 
 scanf("%d", &n);
int *a,*b,*c;
 a = (int *) malloc(n*sizeof(int));
 b = (int *) malloc(n*sizeof(int));
 c = (int *) malloc(n*sizeof(int));
 
// Input Elements of First List;
 for(i=0;i<n;i++)
 {
  scanf("%d",a+i);
 }
 
 //Input Elements of Second List;
 for(i=0;i<n;i++)
 {
  scanf("%d",b+i);
 }
 
 for(i=0;i<n;i++)
 {
  *(c+i) = *(a+i) + *(b+i);
 }
printf("Result is\n");
 
 for(i=0; i<n; i++)
 {
  printf("%d\n",*(c+i));
 }
 
}
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
20
30
40
50
1
2
3
4
5
Result is\n
11\n
22\n
33\n
44\n
55
Result is\n
11\n
22\n
33\n
44\n
55\n
Passed after ignoring Presentation Error
Test Case 2
4
100
200
300
400
400
300
200
100
Result is\n
500\n
500\n
500\n
500
Result is\n
500\n
500\n
500\n
500\n
Passed after ignoring Presentation Error



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...