You are here

C sound program

Sound function produces the sound of a specified frequency. Used for adding music to a C program, try to use some random values in loop, vary delay and enjoy.

Declaration: void sound(unsigned frequency);

C programming code for sound (Turbo C compiler only)

  1. #include <dos.h>
  2.  
  3. int main()
  4. {
  5.    int a;
  6.  
  7.    for (a = 200; a <= 1000; a = a + 20)
  8.    {
  9.       sound(a);
  10.       delay(25);
  11.    }
  12.  
  13.    nosound();
  14.  
  15.    return 0;
  16. }