Hello Everyone, Welcome to my blog for Sharing and Learning together! I hope you have a nice day! :)

MENAMPILKAN DERET BILANGAN PRIMA DENGAN BAHASA C

+ No comment yet

/* ---------------------------------------* 
* PROGRAM MENAMPILKAN DERET BILANGAN PRIMA (TUGAS NO 2)* 
* Dibuat oleh : Eri Nur Sofa * 
* NIM: G.231.13.0139 *
* Tanggal : 02 Juni 2014 * 
*----------------------------------------*/ 

#include <stdio.h>
void main()
{
int n, i, j, flag;
  clrscr();
  printf("PROGRAM MENAMPILKAN DERET BILANGAN PRIMA (TUGAS NO 2)\n");
  printf("=======================================\n");
  printf("Masukan n: ");scanf("%d", &n);
  printf("Bilangan prima antara 1 dan %d : \n", n);
  for(i=1; i<n; ++i)
  {
      flag=0;
      for(j=2; j<=i/2; ++j)
      {
        if(i%j==0)
        {
          flag=1;
          break;
        }
      }
      if(flag==0)
        printf("%d ",i);
     printf("\n");
  }
  printf("=======================================\n");
  getch();
}

Post a Comment