C program and algorithm to print numbers upto a limit

Algorithm

  1. start
  2. read limit
  3. set i=0
  4. if i<=limit
  5. display i
  6. i+1 go to 4
  7. else
  8. stop
Program

#include<stdio.h>
#include<conio.h>   //only for windows users
void main()
{
clrscr();   //only for windows users
int lim,i;
printf("\n enter the limit:\t");
scanf("%d",&lim);
for(i=0;i<=lim;i++)
{
printf("%d\t",i);
}
getch();   \\only for windows users
}

Output

enter the limit: 5
0 1 2 3 4 5

No comments:

Post a Comment