#include
#include
#define SIZE 20
main()
{
int i[SIZE];
int a,b,c,d=0,bil;
clrscr();
printf("INPUT BILANGAN : ");scanf("%d",&bil);
printf("\n\nBilangan Prima dari 1 s/d %d adalah :\n\n",bil);
for(a=1;a<=bil;a++)
{
c=0;
for(b=1;b<=a;b++)
{
if(a%b==0)
c++;
}
if(c==2)
{
d++;
i[d]=a;
printf("%d,",a);
}
}
printf("\n\n\n");
printf("Deret %d Bilangan Prima :\n\n",d);
for(b=1;b<=d;b++)
{
for(a=1;a<=b;a++)
{printf("%d ",i[a]);}
printf("\n");
}
getch();
}
Program Bubble sort
#include
#include
#define SIZE 10
int main()
{
int a[SIZE];
int i,j,n,k,temp;
char d;
clrscr();
printf("Masukkan Bilangan : ");
scanf("%d",&n);
printf("\nMASUKKAN ANGKA\n");
printf("=================\n\n");
for(i=1;i<=n;i++)
{printf("\t");
scanf("%d",&a[i]); fflush(stdin);}
for(i=1;i<=n;i++)
{
k=i+1;
for(j=k;j<=n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\nOUTPUT(BUBLE SORT)\n");
printf("==================\n\n");
for(i=1;i<=n;i++)
{printf("\t%d\n",a[i]);}
getchar();
}
Tidak ada komentar:
Posting Komentar