All pastes #341086 Raw Edit

Unnamed

public cpp v1 · immutable
·published 2007-02-05 08:15 UTC
rendered paste body
// knight.cpp : Defines the entry point for the console application.//#include<iostream.h>#include<conio.h>#include<iomanip.h>const int size = 6;int* a, * b;int k;void initialization(){	a = new int[size];	for (int i = 0; i < size; i++)		a[i] = i;	cout << "Input array is: " << endl;	for ( i = 0; i < size; i++)		cout << setw(4) << a[i];		cout << endl << "Please enter k's value: "; 	cin >> k;	k = k % size;	cout << "======================================" << endl;}void do_shift(){	int new_position;		// tu 0 den size - k - 1 cua b -> tu k den size - 1 cua a.    // tu size - k den size - 1 cua b -> tu 0 den k-1 cua a	b = new int[size];	for (int i = 0; i < size; i ++)	{		new_position = (i+k+size) % size;		cout << "new_position : " << new_position << " gia tri la " << a[new_position] << endl;		b[i] = a[new_position];	}}void print(){	cout << "Result array after shifting will be : " << endl;	for (int i = 0; i < size; i++)	{		cout <<  "b[" << i << "] = " ;		cout << b[i] << endl;	}	cout <<"haha";}void main(){	initialization();	do_shift();	print();	getch();}