//program produces this output , showing carefully how and when…