[ create a new paste ] login | about

Link: http://codepad.org/T6vjaM2y    [ raw code | output | fork ]

appunti2 - C, pasted on May 1:
#include <stdio.h>

char *input_1 = "111";  // al posto di argv[1];

unsigned int
primo (int x)
{
    unsigned int primo = 1;
    int i = 2;
    int j;

    while ((i < x) && primo)
      {
        j = x / i;
        j = x - (j * i);

        if (j == 0)
          {
            primo = 0;
          }
        else
          {
            i++;
          }
      }

    return primo;
}

int
main (int argc, char *argv[])
{
    int x;

    sscanf (input_1, "%i", &x);

    if (primo (x))
      {
        printf ("%i è un numero primo\n", x);
      }
    else
      {
        printf ("%i non è un numero primo\n", x);
      }

    return 0;
}


Output:
1
111 non è un numero primo


Create a new paste based on this one


Comments: