#include<stdio.h>
#include <conio.h>
int main(){
int i,j,b=-1,a=0;
printf("bilangan ganjil : ");
scanf("%d",&i);
j=1;
do
{
a=b;
b=a;
b=a+2;
printf("%d ",b);
j++;
}
while (j<=i);
getch();
return 0;
}
Minggu, 08 April 2012
perulangan bilangan genap pada C
#include<stdio.h>
#include <conio.h>
int main(){
int i,j,b=0,a=0;
printf("bilangan genap : ");
scanf("%d",&i);
j=1;
do
{
a=b;
b=a;
b=a+2;
printf(" %d ",b);
j++;
}
while (j<=i);
getch();
return 0;
}
#include <conio.h>
int main(){
int i,j,b=0,a=0;
printf("bilangan genap : ");
scanf("%d",&i);
j=1;
do
{
a=b;
b=a;
b=a+2;
printf(" %d ",b);
j++;
}
while (j<=i);
getch();
return 0;
}
perulangan c
#include<stdio.h>
#include<conio.h>
int main ()
{
int j,i,k,n;
n=5;
for(i=0;i<=n;i++)
{
for(j=n;j>i;j--)
{
printf(" ");
}
for(k=0;k<=i;k++)
{
printf("*");
}
printf("\n");
}
getch();
return 0;
}
#include<conio.h>
int main ()
{
int j,i,k,n;
n=5;
for(i=0;i<=n;i++)
{
for(j=n;j>i;j--)
{
printf(" ");
}
for(k=0;k<=i;k++)
{
printf("*");
}
printf("\n");
}
getch();
return 0;
}
perulangan for pada c
#include <stdio.h>
#include <conio.h>
int main ()
{
int i,j;
printf ("Masukkan jumlah : ");
scanf ("%d", &i);
for (int c = i; c <= 10; c++ )
{
for (int j = i; j < c; j++ )
{
printf ("%d ", j);
}
printf ("\n");
}
getch ();
return 0;
}
#include <conio.h>
int main ()
{
int i,j;
printf ("Masukkan jumlah : ");
scanf ("%d", &i);
for (int c = i; c <= 10; c++ )
{
for (int j = i; j < c; j++ )
{
printf ("%d ", j);
}
printf ("\n");
}
getch ();
return 0;
}
perulangan pada c
#include<stdio.h>
#include<conio.h>
int main ()
{
int j,i,k,t,n;
n=20;
for(i=1;i<=n;i++)
{
if(i%2==0){continue;}else{
for(j=n;j>i;j=j-2)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("*");
}
printf("\n");}
}
getch();
return 0;
}
Langganan:
Postingan (Atom)