73.5k views
1 vote
C Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is:

User Veech
by
6.0k points

1 Answer

6 votes

Answer:

Written in C Language

#include <stdio.h>

int main() {

int num1, num2;

printf("Enter two integers: ");

scanf("%d", &num1);

scanf("%d", &num2);

if(num1 <= num2){

for(int i = num1; i<= num2; i+=10)

{

printf("%d",i); printf(" ");

}

}

return 0;

}

Step-by-step explanation:

This line declares two integer variables

int num1, num2;

This line prompts user for input of the two numbers

printf("Enter two integers: ");

The next two lines get integer input from the user

scanf("%d", &num1);

scanf("%d", &num2);

The following if statement checks if num1 is less than or equal to num2

if(num1 <= num2){

The following iteration prints from num1 to num2 at an increment of 10

for(int i = num1; i<= num2; i+=10)

{

printf("%d",i); printf(" ");

}

User Tom Metz
by
6.6k points