C Program Code to display selected numbers within a limit


The following C program code displays selected no.s within a limit. Here the sample code displays even no.s within a limit. You can modify the code to make it work for selecting other numbers. 
For eg. If you want to print the multiples of 3 within a limit, you will just have to change the datatype of the variables into float and change the if condition into (i % 3 == 0).

#include<stdio.h>
int main()
{
int a,b,i;
printf("Enter the starting number: ");
scanf("%d",&a);
i=a;
printf("Enter the limit: ");
scanf("%d",&b);
while(i>=a && i<=b)
{
if((i%2)==0)
{
printf("\t%d",i);
}
i=i+1;
}
getch();
return(0);
}
view raw gistfile1.txt hosted with ❤ by GitHub

Comments