Input:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, i;
scanf("%d%d", &a,&b);
for (i=a; i<=b;i++)
printf("%d",i);
printf("\n" );
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, i;
scanf("%d%d", &a,&b);
for (i=a; i<=b;i++)
printf("%d",i);
printf("\n" );
return 0;
}
Output:
1 5
1 2 3 4 5
Loop in another loop (nested loop)
input:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, i,j;
for (j=1; j<=5; j++)
{
scanf("%d%d", &a,&b);
for (i=a; i<=b;i++)
printf("%d",i);
printf("\n" );
}
return 0;
}
Output:
1 5
1 2 3 4 5
4 6
4 5 6
6 9
6 7 8 9
8 10
8 9 10
1 3
1 2 3
Nested loop using while:
input:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, i,j;
for (j=1; j<=5; j++)
{
scanf("%d%d", &a,&b);
while (a<=b)
printf("%d ",a++);
printf("\n" );
}
return 0;
}
output:
1 5
1 2 3 4 5
4 6
4 5 6
6 9
6 7 8 9
8 10
8 9 10
1 3
1 2 3