NPTEL Introduction To Programming In C WEEK4 Programming Assignment 2022

NPTEL Introduction To Programming In C Week 4 All Programming Assignment Solutions | Swayam 2022. With the growth of Information and Communication Technology, there is a need to develop large and complex software.

This is a course in programming in C. No prior programming experience is assumed; however, mathematical maturity at the level of a second year science or engineering undergraduate is assumed.
We emphasize solving problems using the language, and introduce standard programming techniques like alternation, iteration and recursion. We will briefly glimpse the basics of software engineering practices like modularization, commenting, and naming conventions which help in collaborating and programming in teams.
Given a problem, we pay attention to the following questions:
1. What is an algorithmic solution to the problem?
2. How do we translate the algorithm into C code?
3. How efficient is the code?
4. How maintainable is the code?

COURSE LAYOUT
    • Week 1 : Introduction. Straight-Line Code. Variables, Operators, Expressions and Conditionals.
    • Week 2 : Loops
    • Week 3 : Functions
    • Week 4 : One-Dimensional Arrays and Pointers
    • Week 5 : Recursion
    • Week 6 : Multi-dimensional Arrays, Linked Lists.
    • Week 7 : Operating on Files
    • Week 8 : Organizing C projects, working with multiple source directories, makefiles.

Course certificate

The course is free to enroll and learn from. But if you want a certificate, you have to register and write the proctored exam conducted by us in person at any of the designated exam centres.
The exam is optional for a fee of Rs 1000/- (Rupees one thousand only).
Date and Time of Exams: 23 April 2022 Morning session 9am to 12 noon; Afternoon Session 2pm to 5pm.
Registration url: Announcements will be made when the registration form is open for registrations.
The online registration form has to be filled and the certification exam fee needs to be paid. More details will be made available when the exam registration form is published. If there are any changes, it will be mentioned then.
Please check the form for more details on the cities where the exams will be held, the conditions you agree to when you fill the form etc.

CRITERIA TO GET A CERTIFICATE

This course will have an unproctored programming exam also apart from the Proctored exam, please check announcement section for date and time. The programming exam will have a weightage of 25% towards the Final score.

Final score = Assignment score + Unproctored programming exam score + Proctored Exam score

  • Assignment score = 25% of average of best 6 assignments out of the total 8 assignments given in the course. 
  • ( All assignments in a particular week will be counted towards final scoring – quizzes and programming assignments). 
  • Unproctored programming exam score = 25% of the average scores obtained as part of Unproctored programming exam – out of 100
  • Proctored Exam score =50% of the proctored certification exam score out of 100

YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF ASSIGNMENT SCORE >=10/25 AND
UNPROCTORED PROGRAMMING EXAM SCORE >=10/25 AND PROCTORED EXAM SCORE >= 20/50. 

If any one of the 3 criteria is not met, you will not be eligible for the certificate even if the Final score >= 40/100.

Certificate will have your name, photograph and the score in the final exam with the breakup.It will have the logos of NPTEL and IIT Kanpur.

Only the e-certificate will be made available. Hard copies will not be dispatched.

Once again, thanks for your interest in our online courses and certification. Happy learning.

Course Name : “Introduction To Programming In C

Question : 1 

Given two arrays of integers output the largest number in the
first array not present in the second one.

Input: 

The first line contains the size of the first array.
Next line give the contents of the first array.
Next line contains the size of the second array.
Next line give the contents of the second array.

Output Format:
Output must be a single number which is the largest number occurring
in the first array that does not occur in the second. In case there is
no such number, output 0.

Variable Constraints:
The sizes of the arrays are smaller than 20.
Each array entry is an integer which fits an int data type.

Example:
Input:
3
2 3 4
4
1 4 5 7

Output: 3

Input
1
1
2
1 2

Output: 0
				
					#include<stdio.h>
int main()
{
  int m,n,a[20],b[20],i,j,t; 
  scanf("%d",&m); 
  for(i=0; i<m; i++)
  {
    scanf("%d",&a[i]);
  }
  scanf("%d",&n); 
  for(i=0;i<n;i++) 
  {
    scanf("%d",&b[i]); 
  }
  for(i=0;i<m-1; i++)
  {
	for(j=i+1;j<m; j++)
    {
      if(a[i]<a[j])
      {
        t=a[i]; 
        a[i]=a[j];
        a[j]=t;
      }
    }
  }
  for(i=0;i<m;i++)
  {
    for(j=0;j<n; j++)
    {
      if(a[i]==b[j]) 
        break;
    }
    if(j==n)
    {
      printf("%d",a[i]);
      break;
    }
  }
  if(i==m)
    printf("0");
  return 0;
}
				
			

Course Name : “Introduction To Programming In C

Question : 2

Write a program that replaces the occurence of a given character (say c)
in a primary string (say PS) with another string (say s).

Input:
The first line contains the primary string (PS)
The next line contains a character (c)
The next line contains a string (s)

Output:
Print the string PS with every occurence of c replaced by s.

NOTE:
- There are no whitespaces in PS or s. 
- Maximum length of PS is 100.
- Maximum length of s is 10.
				
					#include<stdio.h>
int main() 
{
  char ps[100], temp [100],c ,s[15];
  int i, j,k;
  scanf("%s",ps);
  scanf("\n%c",&c);
  scanf("%s",s); 
  for(i=j=0; ps[i]!= '\0'; i++)
  {
    if(ps[i]==c)
    {
      for (k=0; s[k]!= '\0'; k++)
      {
        temp[j++] =s[k];
      }
    }
    else
      temp[j++]=ps[i];
  }
  temp[j]=0;
  i=0; 
  while(temp[i]!='\0') 
  {
    ps[i] =temp[i];
    i++;
  }
  ps[i]=0; 
  printf("%s",ps); 
  return 0;
}
				
			

Course Name : “Introduction To Programming In C

Question : 3

Given a threshold floating point number and an array of floating point numbers strictly between 0 and 1.
Modify the array with the following rules: If the number is greater than threshold value, change it to 1 and if less than or equal to threshold value, change to 0.
   
Output the sum of the modified array.
Constraint: Array contains atmost 20 elements.
 
Input: First line contains the threshold value.
           Next line gives the size of an array.
           Next line provides the content of an array.
          
Output: Sum of modified array.
 
Example:   Input:
            0.3
            4
            0.1 0.9 0.11 0.98
           
Modified array: 0 1 0 1
 
Output : 2
				
					#include<stdio.h> 
int main()
{
  int n,i, sum=0; 
  float a[20],th;
  scanf("%f",&th); 
  scanf("%d",&n); 
  for(i=0;i<n;i++)
  {
      scanf("%f",&a[i]);
  }
  for(i=0;i<n; i++)
  {
      if(a[i]>th)
        a[i]=1;
      else 
        a[i]=0; 
      sum=sum+a[i];
  }

  printf("%d", sum);
  return 0;
}
				
			

Leave a Reply

Your email address will not be published. Required fields are marked *