Sunday, February 25, 2018

C program : To output the sequence of differences of adjacent pairs of numbers

You are given a sequence of numbers, ending with a -1. You can assume
that are at least two numbers before the ending -1. 

Let us call the sequence x0 x1 ... xn -1.

You have to output the sequence of differences of adjacent pairs of
numbers, as follows: 

x1-x0 x2-x1 ... x_{n}-x_{n-1}


#include<stdio.h>

int main()
{
      int a ,b,diff;
  scanf("%d", &a);
  if(a !=(-1))
  {   
    while(b!= (-1))
  {
       scanf("%d", &b);
      if(b== -1){break;}
    diff=(b-a);
    printf("%d ",diff);
           a=b;
  }
  }
  return 0;
}

Thanks
Happy Computing !

No comments:

Post a Comment

Derivatives stock list at NSE

Complete FNO stock list at NSE. ABB India Ltd ACC Ltd APL Apollo Tubes Ltd AU Small Finance Bank Ltd Aarti Industries Ltd Abbott India Ltd A...