Introduction To Programming In C Online Programming Test April 2022

Introduction To Programming In C Online Programming Test April 2022:- In This Article, we have helped with the online programming test of Introduction to programming in c.

Introduction To Programming In C Online Programming Test April 2022 Session 1 [10 AM to 12 PM]

Q1. You are given a 3×3 matrix of positive integers. You have to determine whether some row is a positive integer multiple of another.

Code:-

#include<stdio.h>
int main()
{
  int arr[3][3];
  int r=0,c=0,f=0,cnt;
  for(int i=0;i<3;i++)
  {
    for(int j=0;j<3;j++)
    {
      scanf("%d",&arr[i][j]);
    }
  }
   for(int i=0;i<3;i++)
  {
     int n=100;
   for(int k=0;k<3;k++)
   {cnt=0;
    r=0;
    c=0;
    f=0;
    
     if(k!=i)
     {
       int l=(arr[k][0]>arr[k][1])?arr[k][0]:arr[k][1];
       int m=(l>arr[k][2])?l:arr[k][2];
         while(cnt<=m)
         {
         if(arr[i][0]*cnt==arr[k][0] && arr[i][1]*cnt==arr[k][1] && arr[i][2]*cnt==arr[k][2] )
         {
           r=i;
           if(cnt<n)
           {
             n=cnt;
             c=k;
           }
           f=1;
           break;
           
         }
           cnt++;
         }
         
       }
     if(f==1)
     {
       break;
     }
     }
     if(f==1)
     {
       break;
     }
   }
  int x=(r>c)?r:c;
  int y=(r<c)?r:c;
  printf("%d#%d",y,x);
  return 0;
}

Q2. You are given a “secret” string, and you are given a “guess” string. Both strings have exactly 5 characters.

Code:-

#include<stdio.h>
int main()
{
  int I=0;
  int J=0;
  char secret[6];
  char guess[6];
  scanf("%s",secret);
  scanf("%s",guess);

  for(int i=0;i<5;i++)
  {
    if(secret[i]==guess[i])
      I++;
  
  }
  for(int i=0;i<5;i++)
  {
    if(guess[i]!=secret[i])
    {
      for(int j=0;j<5;j++)
        {
          if(guess[i]==secret[j])
            J++;
        }
    }
   
  }
  printf("%d#%d",I,J);
  return 0;
}

Q3. Detect whether a given positive integer N can be written as a product of powers of 2, 3 and 5. That is, check whether N is exactly equal to

Code:-

#include<stdio.h>
int main()
{
  int N,i=0,j=0,k=0;
  scanf("%d",&N);
  while(N>1)
  {
    if(N%2==0)
    {
      i++;
      N=N/2;
    }
    else if(N%3==0)
    {
      j++;
      N=N/3;
    }
    else if(N%5==0)
    {
      k++;
      N=N/5;
    }
    else
    {
      N=-1;
      break;
    }
  }
  if(N==-1)
    printf("no");
  else
    printf("%d#%d#%d",i,j,k);
  return 0;
}

Introduction To Programming In C Online Programming Test April 2022:- In This Article, we have helped with the online programming test of Introduction to programming in c.

Introduction To Programming In C Online Programming Test April 2022 Session 2 [8 PM to 10 PM]

Q1. You are given a 3×3 matrix, with the first row and the first column filled with positive integers. The remaining entries are 0. You have to “complete” the matrix in the following way.

Code:-

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a[3][3];
    int b[2][2];
    for(int i =0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            scanf("%d", &a[i][j]);
        }
    }

    for(int i = 1; i < 3; i++ )
    {
        for (int j = 1; j < 3;  j++)
        {
            a[i][j] = a[i - 1][j] + a[i][j -1];
        }
        
    }
    printf("%d", a[2][2]);
    
}

Q2. You are given a string, whose elements can be English letters (capital or small letters), numerical digits, or other characters. These are called special characters. You have to output the number of digits in the string.

Code:-

#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
#include<string.h>
int main()
{
    char a[100];
    int N, j = 0;
    scanf("%s", a);
    N = strlen(a);
    for (int i = 0; i < N; i++)
    {
        if (isdigit(a[i]))
        {
            j ++;
        }
    }
    printf("%d", j);

}

Q3. You are given a sequence of positive numbers terminated with a -1. Some initial portion of the sequence is monotone non-decreasing. You can assume that the non-decreasing part has at least 2 elements and the part after that also has at least one element.

Code:-

#include <stdio.h>
int main(void){
    int arr[999];
    int pos = 0;
    do{
        scanf("%d",&arr[pos]);
        if(arr[pos] < arr[pos-1])
            break;
    } while (arr[pos++] != -1);
    printf("%d",pos-1);
    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 Online Programming Test April 2022:- In This Article, we have helped with the online programming test of Introduction to programming in c.

5 thoughts on “Introduction To Programming In C Online Programming Test April 2022”

  1. Online exam Q1
    You are given a 3×3 matrix of positive integers. You have to
    determine whether some row is a positive integer multiple of
    another.

    If row i is an integer multiple of row j, then you have
    to output
    p#q where p is the minimum of (i,j) and q is the maximum of (i,j).

    If there are multiple possibilities for i and j, you have to print for the
    smallest i and the smallest j.

    Otherwise, you have to output
    0#0

    #include
    int main()
    {
    int arr[3][3];
    int r=0,c=0,f=0,cnt;
    for(int i=0;i<3;i++)
    {
    for(int j=0;j<3;j++)
    {
    scanf("%d",&arr[i][j]);
    }
    }
    for(int i=0;i<3;i++)
    {
    int n=100;
    for(int k=0;karr[k][1])?arr[k][0]:arr[k][1];
    int m=(l>arr[k][2])?l:arr[k][2];
    while(cnt<=m)
    {
    if(arr[i][0]*cnt==arr[k][0] && arr[i][1]*cnt==arr[k][1] && arr[i][2]*cnt==arr[k][2] )
    {
    r=i;
    if(cntc)?r:c;
    int y=(r<c)?r:c;
    printf("%d#%d",y,x);
    return 0;
    }

  2. #include
    #include

    int main(void) {
    // your code goes here
    int a[3][3];
    int p=0,q=0;
    bool check=false;
    for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
    scanf("%d", &a[i][j]);
    }
    }
    for(int i=0;i<3&&check==false;i++){
    if(a[i][0]==0&&a[i][1]==0&&a[i][2]==0){
    if(i==0||i==1){
    p=0;
    q=1;
    check=true;
    }
    else{
    p=0;
    q=2;
    check=true;
    }
    }
    else if(((a[i][0]*a[i][1]*a[i][2])!=0)){
    for(int j=i+1;j<3&&check==false;j++){
    if((a[j][0]*a[j][1]*a[j][2])!=0){
    int temp=0;
    if((a[i][0]%a[j][0])==0){
    temp=a[i][0]/a[j][0];
    if((a[i][1]==a[j][1]*temp)&&(a[i][2]==a[j][2]*temp)){
    p=i;
    q=j;
    check=true;
    }
    }
    else if((a[j][0]%a[i][0])==0){
    temp=a[j][0]/a[i][0];
    if((a[j][1]==a[i][1]*temp)&&(a[j][2]==a[i][2]*temp)){
    p=i;
    q=j;
    check=true;
    }
    }
    }
    }
    }
    }

    printf("%d#%d", p, q);
    return 0;
    }

    Correct code of question 1 is this

Leave a Comment