void Learn::test4() { int wallet1 = 300; int wallet2 = 350; cout << "wallet1 = $" << wallet1<<endl; cout << "wallet2 = $" << wallet2<<endl; swapr(wallet1,wallet2); cout << "wallet1 = $" << wallet1<<endl; cout << "wallet2 = $" << wallet2<<endl; swapp(&wallet1, &wallet2); cout << "wallet1 = $" << wallet1<<endl; cout << "wallet2 = $" << wallet2<<endl; swapv(wallet1,wallet2); cout << "wallet1 = $" << wallet1<<endl; cout << "wallet2 = $" << wallet2<<endl; }
int main() { int x, y; x=3; y=7; swap(x,y); cout << x << " " << y << "\n"; int *f=&x,*g=&y; swapp(f,g); cout << *f << " " << *g << "\n"; // question Ex 2 increment(x,y,5);// f,g point to x,y anyways cout << *f << " " << *g << "\n"; increment(*f,*g,5);// f,g point to x,y anyways cout << *f << " " << *g << "\n"; // question ex 3 string str = ""; int add = 0; vector<int> *vec = new vector<int>(); while (add>-1) { getline(cin,str); add = atol(str.c_str()); vec->push_back(add); cout << add << "\n"; } string s; char tmpStr[50]; for (int i=0;i<vec->size();i++) { s.append(" * "); // quite odd that i have to use (*vec)[i] . cout << (*vec)[i] << "\n"; sprintf( tmpStr, "%d", (*vec)[i] ); s.append(tmpStr); } cout << s << "\n"; }
main() { char *a="vacances"; char *b="vendredi" ; printf( "\na pointe sur %s b pointe sur %s", a,b ); swapp(&a,&b) ; printf( "\napres echange: a pointe sur %s b pointe sur %s\n", a,b ); }
GivensRotation::GivensRotation(const Random dummy, const int n) { uniform_int_distribution<int> distri(0, n - 1); uniform_real_distribution<FIELD> distrr(0, 1); i1 = distri(randomNumberGenerator); i2 = i1; while (i2 == i1) { i2 = distri(randomNumberGenerator); } if (i2 > i1) swapp(i1, i2); cos = distrr(randomNumberGenerator); sin = sqrt(1 - cos * cos); }
void bubblesort() { int i, j, swapped; for(i = 0; i <= n - 1 && swapped;i++) { swapped = 0; for(j = n - 1; j > i; j--) { if(arr[j].mark < arr[j-1].mark) { swapp(&arr[j], &arr[j-1]); swapped = 1; } } } }
// elem(a,i,j) -> elem(a,j,i) void transpose2(array a){ swap(&a->dims[0],&a->dims[1]); swap(&a->weight[0],&a->weight[1]); if (a->translate) swapp(&a->translate[0], &a->translate[1]); }