Problem Solving Through Programming in C Week 12: Programming Assignments Jan-Jun 2022

 NPTEL PROGRAMMING ASSIGNMENTS

Problem Solving Through Programming in C


Week-12: Program 01

Due Date of Submission 2022-04-21, 23:59 IST
Write a program in C to find the factorial of a given number using pointers.



#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",num1, fact);          return 0;         }




 

 



Week-12: Program 02

Due Date of Submission 2022-04-21, 23:59 IST
Write a C program to print the Record of the Student Merit wise in descending order.
Here a structure variable is defined which contains student rollno, name and score



#include<stdio.h>
struct student
{
int rollno;
char name[20];
int score;
};
void main()
{
struct student s[20];
int i, n;
scanf("%d" ,&n);
for(i=0;i<n;i++)
{
scanf("%d", &s[i].rollno);
scanf("%s", s[i].name);
scanf("%d", &s[i].score);
}


 

 

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); }  }





Week-12: Program 03

Due Date of Submission 2022-04-21, 23:59 IST
Write a C program to store n elements using Dynamic Memory Allocation - calloc() and find the Largest element.


#include <stdio.h> #include <stdlib.h>  int main() {     int n;      float *element;      scanf("%d", &n); //Total number of elements


 

 



Week-12 Problem 04

Due Date of Submission 2022-04-21, 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.

For example: 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.






#include<stdio.h>
#include<stdlib.h>
void main()
{
 int i,n;
 scanf("%d", &n);

 

 


printf("Result is\n");   for(i=0; i<n; i++)  {   printf("%d\n",*(c+i));  }  }


Post a Comment (0)
Previous Post Next Post