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

Sacred Thought

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...