Вот, пожалуйста.
#include <stdlib.h>
#include <stdio.h>
typedef struct Nodo
{
int d;
struct Nodo *next;
} Nodo;
int push_front( Nodo **head, int value )
{
Nodo *tmp = malloc( sizeof( Nodo ) );
int success = tmp != NULL;
if ( success )
{
tmp->d = value;
tmp->next = *head;
*head = tmp;
}
return success;
}
Nodo * prodotto_pos( const Nodo *first, const Nodo *second )
{
static int pos = 0;
Nodo *current = NULL;
if ( first != NULL && second != NULL )
{
++pos;
if ( ( first->d + second->d ) % pos == 0 )
{
current = malloc( sizeof( Nodo ) );
current->d = first->d * second->d;
current->next = prodotto_pos( first->next, second->next );
}
else
{
current = prodotto_pos( first->next, second->next );
}
--pos;
}
return current;
}
void display( const Nodo *head )
{
for ( ; head != NULL; head = head->next )
{
printf( "%d -> ", head->d );
}
puts( "NULL" );
}
int main( void )
{
Nodo *first = NULL;
Nodo *second = NULL;
int a1[] = { 3, 4, 2, 7, 5, 6, 11, 16, 7, 2 };
const size_t N1 = sizeof( a1 ) / sizeof( *a1 );
int a2[] = { 0, 2, 2, 6, 2, 12, 2 };
const size_t N2 = sizeof( a2 ) / sizeof( *a2 );
for ( size_t i = N1; i != 0; --i )
{
push_front( &first, a1[i-1] );
}
for ( size_t i = N2; i != 0; --i )
{
push_front( &second, a2[i-1] );
}
display( first );
display( second );
Nodo *product = prodotto_pos( first, second );
display ( product );
}
Вывод программы
3 -> 4 -> 2 -> 7 -> 5 -> 6 -> 11 -> 16 -> 7 -> 2 -> NULL
0 -> 2 -> 2 -> 6 -> 2 -> 12 -> 2 -> NULL
0 -> 8 -> 72 -> NULL