Introduction To Programming In C NPTEL Assignment 6 Answers

Introduction To Programming In C NPTEL Assignment 6 Answers 2022:- All the Answers are provided here to help the students as a reference, You must submit your assignment at your own knowledge.

What is Introduction To Programming In C?

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. 

CRITERIA TO GET A CERTIFICATE

Average assignment score = 25% of the average of best 6 assignments out of the total 8 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100

Final score = Average assignment score + Exam score

YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF THE AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.

Assignment No.Answers
Introduction To Programming In C Assignment 1Click Here
Introduction To Programming In C Assignment 2Click Here
Introduction To Programming In C Assignment 3Click Here
Introduction To Programming In C Assignment 4Click Here
Introduction To Programming In C Assignment 5Click Here
Introduction To Programming In C Assignment 6Click Here
Introduction To Programming In C Assignment 7Click Here
Introduction To Programming In C Assignment 8Click Here

Introduction To Programming In C NPTEL Assignment 6 Answers 2022:-

Q1. We say that a string ‘s’ is an anagram of another string ‘t’ if the letters in ‘s’ can be rearranged to form ‘t’.

Code:-

#include<stdio.h>
#include<string.h> 
int main()
{
  char a[100], b[100];
  int max=0,i=0; 
  scanf("%s %s", a,b);
  int count1[26] = {0}, count2[26] = {0};
  
  while (a[i] != '\0')

  {

     count1[a[i] - 'a'] ++;
     i++;
   } 
   i = 0;
   while (b[i] != '\0') 
   {
     count2[b[i] -'a']++;
     i++;
   }

   for (i = 0; i<strlen(a); i++) 
   {
      if (count1[i] != count2[i])
      {
        printf("-1");
        return 0;
      }
      if(a[i] == b[i])
         max++;
   }
  printf("%d",max);
  return 0;
}

Q2. In a string, a “run” is a substring with consisting of consecutive
occurrences of the same character. For example, the string
“mississippi” contains the following runs – “ss”, “ss” and “pp”.

Code:-

#include<stdio.h> 
#include<string.h>
int main()
{
  char s[100]; 
  int i,j,max=1,count;
  scanf("%s",s); 
  for(i=0;i<strlen(s)-1;i++)
  {
    j=i+1; 
    count=1;
    while((j<strlen(s))&&(s[i]==s[j])) 
    {
      count++;
      j++;
    }
    if(max<count)
      max=count; 
    i=j-1;
  }
  printf("%d", max);
  return 0;
}

Q3. In this question, you are given two positive integers M and N, where M < N. You may assume that N is less than or equal to 100.

Code:-

#include<stdio.h> 
int main()
{ 
  int i=1,r,d=0,a[100]={0},M,N,p=1; 
  scanf("%d%d",&M,&N); 
  while(i<=N)
  {
    r=(M*p)%N; 
    if(a[r]==0) 
      d++;
     a[r]=a[r]+1; 
    i++; 
    p=p*2;
  } 
  printf("%d", d); 
  return 0;
}

Disclaimer:- We do not claim 100% surety of solutions, these solutions are based on our sole expertise, and by using posting these answers we are simply looking to help students as a reference, so we urge do your assignment on your own.

For More NPTEL Answers:- CLICK HERE

Join Our Telegram:- CLICK HERE

Introduction To Programming In C NPTEL Assignment 6 Answers 2022:- All the Answers are provided here to help the students as a reference, You must submit your assignment to your own knowledge.

1 thought on “Introduction To Programming In C NPTEL Assignment 6 Answers”

Leave a Comment