Write a C program to print all numbers between a and b (a and b inclusive) using for loops.
Input Format:
Input consists of 2 integers. The first integer corresponds to a and the second integer corresponds to b.
Output Format:
Refer Sample Input and Output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to output]
Sample Input and Output 1:
Enter the value of a
10
Enter the value of b
4
10
9
8
7
6
5
4
Sample Input and Output 2:
Enter the value of a
4
Enter the value of b
10
4
5
6
7
8
9
10
no code?????
ReplyDelete#include
ReplyDelete02
int main()
03
{
04
int a,b,i;
05
printf("Enter the value of a\n");
06
scanf("%d",&a);
07
printf("Enter the value of b\n");
08
scanf("%d",&b);
09
if(a>=b)
10
{
11
for(i=a;i>=b;i--)
12
{
13
14
printf("%d\n",i);
15
16
}
17
}
18
19
if(a<=b)
20
{
21
for(i=a;i<=b;i++)
22
{
23
printf("%d\n",i);
24
}
25
}
26
27
return 0;
28 }
#include
ReplyDeleteint main()
{
int a,b,i;
printf("Enter the value of a\n");
scanf("%d",&a);
printf("Enter the value of b\n");
scanf("%d",&b);
if(a>=b)
{
for(i=a;i>=b;i--)
{
printf("%d\n",i);
}
}
if(a<=b)
{
for(i=a;i<=b;i++)
{
printf("%d\n",i);
}
}
return 0;
}
#include
ReplyDeleteint main()
{
int a, b, i;
printf("Enter the value of a\n");
scanf("%d",&a);
printf("Enter the value of b\n");
scanf("%d", &b);
if(a>=b)
{
for(i=a;i>=b;i--)
{
printf("%d\n", i);
}
}
else
{
for(i=a;i<=b;i++)
{
printf("%d\n",i);
}
}
return 0;
}