Click here to Skip to main content
15,886,052 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#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;
}


What I have tried:

I am very new to coding, I would love it if you help
Posted
Updated 6-May-21 6:59am
Comments
Rick York 6-May-21 12:39pm    
Yes.

The C equivalent of iostream is stdio.h. It looks like most of the work involves rewriting the lines that use cin and cout to use stdio.h. See here[^] and here[^].

EDIT: I see from your comment above that you've figured this out.
 
Share this answer
 
v2
Sorry, this site does not provide a conversion service. And to be honest there is almost nothing that needs to be changed. Pick up a book on C, or an online tutorial, and you will see how to do basic input and output.
 
Share this answer
 
Comments
Member 15186910 6-May-21 12:45pm    
I think if ı use scanf and printf functions that would be enough

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900