#include "stdio.h"
int *fonction (int *p_nb, int v[], size_t taille)
{
int *p = NULL;
int somme = 0;
int g = 0;
if (p_nb != NULL)
{
while (*p_nb > 0)
{
somme += *p_nb;
somme %= 10;
*p_nb /= 10;
}
}
{
size_t i = 0;
for (i = 0; i < taille; ++i)
{
printf ("%3d", v[i]);
if (v[i] == somme)
{
g = 1;
p = &v[i];
}
}
printf ("\n" );
}
return (g ? p : NULL);
}
int main (void)
{
int v[] =
{1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41};
int nb = 12;
int *p = fonction (&nb, v, sizeof v / sizeof *v);
if (p != NULL)
{
printf ("*p=%d nb=%d\n", *p, nb);
}
else
{
printf ("error\n" );
}
return 0;
}
|