Write a program to list all the integers between two integers l and r (including l and r). L and r can be any integer between 1 and 100.
Answers
Answered by
1
Answer:
#include <stdio.h>
int main(void) {
// Define the two integer variables
int L,R;
int i;
// Get L and R from the user
scanf("%d", &L);
scanf("%d", &R);
// the logic to print all integers between L and R
for(i=L;i<=R;i++){
printf("%d ",i);
}
return 0;
}
Answered by
2
Below are the c program for the above question---
Explanation:
#include <stdio.h>// include a header file
int main() // define main function
{
int l,r; // declare two variable.
scanf("%d %d",&l,&r); // take input of two variable
while(r>=l) // while loops
{
printf("%d\n",l); // print the counting
l++; // increment
}
return 0; // return statement
}
Output:
- If the user inputs 1 and 5 then it prints 1 to 5 (including 1 and 5).
- If the user inputs 1 and 100 then it prints 1 to 100 (including 1 and 100).
Code Explanation:
- Firstly we declare the two variable l and r of integer types (as the question suggests) and take the inputs for these two variables by the help of scanf statement.
- Then the while loop executes with "(r-l)+1" times and prints every number starting from l and ends in r including n and r value by the help of printf statement.
Learn More:
- Definition of C Program: brainly.in/question/3999878
- C program: https://brainly.in/question/12329234
Similar questions