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;
}
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