Search code examples
cloopsincrement

How to design looping number sequence(increment)?


I want make a program to print the number sequence from beginning to end with a negative increment specified.

Input format:

I Put a single line consisting of three integers: the beginning, the negative increment, and end sequence. (ex: scan 9 -2 3

Output format:

Output a sequence of numbers from start to finish is printed per line. End output with a newline character.(it will be: 9 7 5 3

Here is the solution:

 #include<stdio.h>
int main(void)
{
  int start,step,end,i;
  scanf("%d %d %d",&start,&step,&end);
  for(i=start;i>=end;i+=step)
    printf("%d ",i)
  printf("\n");
}

Solution

  • #include<stdio.h>
    int main(void)
    {
      int start,step,end,i;
      scanf("%d %d %d",&start,&step,&end);
      for(i=start;i>=end;i+=step)
        printf("%d ",i)
      printf("\n");
    }