Sunday, September 13, 2020

Introduction to Programming in C week 1 NPTEL(JULY - DEC 2020) assignmnet solution

 Question 1 :

#include<stdio.h>


void  main()

{

  int arr[4];

  for(int i=0; i<3; i++)

    scanf("%d",&arr[i]);    //To take input.

  

  int sum = arr[0] + arr[1];

  

  if(sum>arr[2]) //if statement to check wether third number is smaller than the sum of

    printf("1"); //first two.

  else 

    printf("0");

}



Question 2 :

#include<stdio.h>


void main()

{

  int m,n;

  scanf("%d",&m);

  scanf("%d",&n);

  

  int rem = m%n;  //% is used to find the remainder.

  

  if(rem==1)

    printf("1");

  else 

    printf("0");

  

}


Question 3:

#include<stdio.h>


void main()

{

  float arr[4];

  

  for(int i=0; i<3; i++)

    scanf("%f",&arr[i]);

  

  //To check wether the triplet is strictly increasing or decreasing or none.

  

  if(arr[0]>arr[1]&&arr[1]>arr[2])

    printf("1");

  else if(arr[2]>arr[1]&&arr[1]>arr[0])

    printf("1");

  else

    printf("0");

}

  

0 Comments:

Post a Comment