Cari Blog Ini

12 Agustus 2016

Contoh Penggunaan Syntax - DO WHILE

 #include <stdio.h>  
 #include <conio.h>  
   
 void main ()  
 {  
      int an,input[10], index,i;  
      int status;  
   
      index = 0;  
      clrscr ();  
      do {  
           gotoxy ( 1,1 );  
           printf ("Masukkan banyak array nya [1..5]= ");  
           fflush (stdin );  
           clreol ();  
           scanf ("%d", &an );  
           } while ( an < 1 || an > 5 );  
   
      for ( i=0; i<an; i++ )  
      {  
                gotoxy ( 3,2+i);  
                printf ("input ke - %d = ", i+1);  
                clreol ();  
                scanf ("%d", &input[i]);  
   
   
       do {  
           gotoxy (4,9 );  
           fflush (stdin);  
           clreol ();  
           printf ("mau masuk ke array yang mana = ");  
           scanf ("%d", &index );  
                } while ( status == index );  
   
       do {  
           gotoxy (4,9 );  
           fflush (stdin);  
           clreol ();  
           printf ("mau masuk ke array yang mana = ");  
           scanf ("%d", &index );  
                } while ( index < 0 || index > 4);  
   
   
           gotoxy (10,12+i );  
           printf ("array ke - %d = %d ", index, input [i] );  
           status = index;  
   
   
      }  
   
   
   
   
   
      getch ();  
   
   
 }