Here is the converted code, using
printf
and
scanf
to replace C++'s
cout
and
cin
respectively.
#include <stdio.h>
#define N 10
int main()
{
int array[N], p, q;
for (int i = 0; i < N; i++)
array[i] = i;
printf("For instance, given elements are ");
for (int i = 0; i < N; i++)
printf("%d ", array[i]);
printf("\n");
int r = 0;
scanf("%d", &p);
while (p>0)
{
scanf("%d", &q);
if (p >= 0 && p < N)
{
for (int i = 0; i < N; i++)
if (array[i] == p)
array[i] = q;
printf("\n%d %d\n", p, q);
for (int i = 0; i < N; i++)
printf("%d ", array[i]);
printf("\n");
}
}
return 0;
}