blog visitors

The program determines prime numbers

The progam determinet prime numbers


C language
 
Program Contents:
 #include <stdio.h>

int main(void) {
    int i, num, flag;

    printf(" \n");
    printf("       DETERMINING THE NUMBERS PRIMA        \n");
    printf("____________________________________________\n");
    printf("Insert numbers: \n");
    scanf("%d", &num);

    if(num < 2) {

       
/ / If the number is less than 2,
      / / Set flag to false (not prime)


        flag = 0;
    } else if(num > 3) {

        //
If the number is more than 3,
      / / Do loop to divide these numbers
     


        i = 2;
        do {
           

             / / Do operations modulo
          / / Operation result 0 (no trace)


            flag = num % i++;

        } while((i < (num / 2)) && flag);

       
/ / Loop as long as i is less than half the number
      / / And the flag is true

    }
   

    //
Show results

   
    if(flag) {
        printf("Prima");
    } else {
        printf("No Prima");
    }

    return 0;
}

Output Results



2 komentar:

Inzar Salfikar mengatakan...

blognya bagus thank infonya.

Unknown mengatakan...

thank..bro

Posting Komentar

Terimakasih Atas Komentarnya semoga berguna demi blog ini