c++ - Error subtracting values -


i have problem subtraction output should be

1 5 13 16 17 > 1 5 13 16 17

4 8 3 1 > 4 8 3 1

4 5 2 want > 5 2 1

1 3 > 2 1

2           right side >             1 

but can see different output, can tell me im wrong , missing need hints or tips. in advance :)

here code:

#include <iostream> #include <stdlib.h>  using namespace std;  int input[10]; int dif[10]; int fin;  int dami; int space;  int i; int j; int b = 0;   int main() { cout << "enter 10 numbers,max 10:\n"; cin >> dami; if (dami > 10) {     cout << "input exceeds limit try again\n";     system("pause");     system("cls");     main(); } else {     cout << "input test case:\n";     (i = 0; <dami; i++)     {         cin >> input[i];          if (input[i] > 100000)         {             cout << "\ninput exceeds limit";             system("pause");             system("cls");             main();         }     }      cout << "\n";     (int z = 0; z < dami; z++)     {         cout << input[z] << "  ";        } /*  (space = 0; space < dami - i; ++space)     {          cout << " ";     }*/     cout << "\n";     (i = 0; < dami; i++)     {          (j = i; j < dami -1;j++)         {             //subtraction part             dif[j] = input[j+1] - input[j];                  fin = dif[j+1] - dif[j];                  if (fin < 0)                 {                     fin = fin * -1;                 }                  cout << " " << fin;          }          cout << "\n";      } } cout << "\n"; system("pause");  } 

first, read user input , if sane, place array.

then pass input array , number of elements contains recursive function such this:

void diff1(int items[], int count) {     if (count > 0)     {         (int n=0; n<count; n++)         {             cout << items[n] << " ";             items[n]=abs(items[n]-items[n+1]);         }          cout << "\n";         diff1(items, --count);     } } 

&here a minimal implementation of function.

(nb: i'm sure can figure out fancy indentation may require :p)


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -