***  massimo di un vettore

#include <stdio.h>

#define MAXN 100

int main ()

{ 
   int v[MAXN];
   int i,n,max,a;

   scanf("%d", &n);
   if (n > MAXN)exit(1);
    for (i=0; i < n; i++)
       {scanf("%d", &a);
        v[i]=a;}
    max=v[0];
    for (i=1; i < n; i++)
       {if (max < v[i]) max=v[i];}
printf("max is %d\n", max);
return(0);

}

*** fattoriale

#include <stdio.h>
#include <stdlib.h>

int fact( int n ) 
{
  if ( n == 0 )
    return 1;
  else
    return n * fact( n - 1 );
}

int main ()

{ 
   int n;

   printf("Input n : ");
   scanf("%d", &n );
   printf("n! = %d\n", fact(n));
   return(0);
}

***   fibonacci ricorsivo

#include <stdio.h>
#include <stdlib.h>

int fib( int n ) 
{
  if ( n == 0 )
    return 0;
  else
     if (n==1) 
      return 1 ; else return fib(n-1)+fib(n-2);
}

int main ()

{ 
   int n;

   printf("Input n : ");
   scanf("%d", &n );
   printf("fib(n)= %d\n", fib(n));
   return(0);
}

****   fibonacci iterativo

#include <stdio.h>
#include <stdlib.h>

int fib( int n ) 
{  int f[3];
   int i;

  f[0]=0;
  f[1]=1;
  if ( n == 0 )
    return 0;
  else
     if (n==1) 
      return 1 ; 
          else 
          for (i=0; i < n-1; i++){f[2]=f[1]+f[0];
                                f[0]=f[1];
                                f[1]=f[2];}
                  return f[2];
}

int main ()

{ 
   int n;

   printf("Input n : ");
   scanf("%d", &n );
   printf("fib(n)= %d\n", fib(n));
   return(0);
}

*** connessione di un grafo

#include <stdio.h>
#include <stdlib.h>

#define MAXN 100

int d[MAXN];
   int adj[MAXN][MAXN];
   int stack[MAXN];
   int marked[MAXN];
   int i,j,n,m,stp,k,h,markn;

int readdata()
{   int a,b;
   scanf("%d%d", &n,&m);
   if (n > MAXN)exit(1);
   for (i=0; i < n; i++){ d[i]=0;marked[i]=0;}
   for (i=0; i < m; i++)
       {scanf("%d%d", &a,&b);
        adj[a][d[a]]=b;
        adj[b][d[b]]=a;
        d[a]++;
        d[b]++;}
return(0);
}

int main ()

{ 

   readdata();
   for (i=0; i < n; i++)
       {printf("nodes adjacent to %d\n", i);
         for (j= 0; j < d[i]; j++)
           {printf(" %d\n", adj[i][j]);
            }
       }

    marked[0]=1;
    markn=1;
    stack[0]=0;
    stp=1;
    k=0;
    while((stp > 0)  && (markn < n) )
      {
       stp--;
       k=stack[stp];
       for (i=0; i< d[k]; i++)
         {h=adj[k][i];
          if (marked[h]==0)
             {marked[h]=1;
              markn++;
              stack[stp]=h;
              stp++;}
          }

       }
if (markn == n) printf("graph connected \n"); else printf("graph not connected\n" );

   return(0);

}