#include <iostream> #include <cstdlib> void reverse(int *array1, int position, int *array2, int len); void fill_table(int table[10][10]) { for(int i=0; i<10; i++) { for(int j=0; j<10; j++) { ((table+i)+j) = 1 + (rand()%9); } } ((table+9)+9) = 0; } void print_table(int table[10][10]) { for(int i=0; i<10; i++) { for(int j=0; j<10; j++) { cout << ((table+i)+j) << " "; } cout << "\n"; } } int find_and_replace_array(int *array1, int *array2, int len1, int len2) { int i=0,j=0,position; for(i=0; i<len2; i++) { for(j=i; j<len1; j++) { if(*(array2+i) == *(array1+j)) { if(i==0) position = j; break; } } if(j == len1) { return -1; } } reverse(array1,position,array2, len2); return position; } void reverse(int *array1, int position, int *array2, int len) { for(int i=position; i<len+position; i++) { *(array1+i) = *(array2+len+position-1-i); } } void find_and_replace_table(int table[10][10], int *array, int len1, int len2) { } int main() { int table[10][10]; fill_table(table); print_table(table); int total_element; cout << "\nEnter number of element to find from table : "; cin >> total_element; cout << "Enter " << total_element << " elements : "; int array2[total_element]; for(int i=0 ;i <total_element ;i++) cin >> array2[i]; int position; for(int i=0; i<10; i++) { position = find_and_replace_array(*(table+i) ,array2, 10, total_element); if(position != -1) cout << "given array2 is at "<< i+1 << "th row and "<< position+1 << "th column in the table" <<endl; } cout <<"\n"; cout << "Replaced table : "<< endl; print_table(table); return 0; }
iostream
stdio.h
cin
cout
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)