The following code in C works perfectly fine. sleep(n) in C takes the argument n as integer, the pattern so produced by the code is fast and at sleep(1) is very slow. I want to go with something in between maybe like sleep(0.5). Is there someway to do it ????? I have Windows OS
#include <stdio.h>
#include <stdbool.h>
#include <direct.h>
void main()
{
char ch='*';
int i=0;bool flag=true;
while(0<i<10)
{
if(flag)
{
++i;
for(int j=0;j<i;j++) //For increaing-pattern
{
printf("%c",ch);
}
printf("n");
if(i==10)
{
sleep(1);
flag=!flag;
}
}
else if(!flag)
{
--i;
for(int j=i;j>-1;j--) //For increaing-pattern
{
printf("%c",ch);
}
printf("n");
if(i==0)
{
sleep(1);
flag=!flag;
}
}
}
}
As mentioned before the program is printing way too fast, and way too slow at sleep(1).
New contributor
AbhishekSingh1604 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2