Counter Program in C Language | Wave the world

Counter Program in C Language

Hello friends... today i'm going to write a simple C code of Counter.

//--------------COUNTER----------------//

#include<stdio.h>
#include<conio.h>
void counter(int,int);
void bin(int);
int bit;
int main()
{

int cl,sst;
printf("****This is a 1 TO 10 bit counter****\n");
printf("Enter the no of bit\n");
scanf("%d",&bit);
printf("Enter the no of cycles\n");
scanf("%d",&cl);
printf("Enter the starting stage\n");
scanf("%d",&sst);
counter(sst,cl);
getch();
}
void counter(int sst,int cl)
{
int i,j=sst,count=0;
for(i=0;i<cl;i++)
{
sleep(1000);
if(j==512)
{
bin(j);
j=0;
count++;
}
else
{
bin(j);
count++;
j++;
}
}
}
void bin(int j)
{
int range=bit;
int a[20]={0,0,0,0,0,0,0,0,0,0},i=0,t;
while(j>0)
{
a[i]=j%2;
j=j/2;
i++;
}
for(t=range-1;t>=0;t--)
printf("%d",a[t]);
printf("\n");
}


OUTPUT:

























Enjoy :)

0 comments:

Post a Comment

 

Pro

About