-3

I'm student and found this code on Internet. Can anyone explain algorythm used here?

#include<stdio.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>

void main()
{
    int count=50;
    clrscr();
    while(count--)
    {
        sound(10*random(100));
        delay(75);
        nosound();
        textattr(random(16)+'a'+BLINK);
        cprintf("*");
    }
}
hyde
  • 60,639
  • 21
  • 115
  • 176

1 Answers1

0

Looks like Turbo C code. sound will set the "PC beeper" playing given frequency, so the code will produce 50 random tones in the loop. It will also use textattr to select random color (most common text modes had 16 fixed colors, random(16) is for that reason) with blink attribute set and print an asterisk 50 times along with the sounds. This will require a real DOS text mode which actually supports blinking characters, in modern console window there will be no blinking.

Also, the include files and libraries are not standard C libraries, so basically code requires Turbo C to work without modification. The code is from simpler era of PC software, where applications had entire computer for themselves, and often used text mode.

hyde
  • 60,639
  • 21
  • 115
  • 176
  • hmmm... yea thanks but ..i know while(such as a==5) or while (any kinds of relation ) but how "while (count--) " works ; – Debajyoti Dev Jan 22 '15 at 20:15
  • 1
    Ah. Well, that is pretty basic C... It first uses the current value of `count`, then *post-decrements* `count`. Here value is used in condition, 0 is false and all other values are true. – hyde Jan 22 '15 at 20:24