Wednesday, February 20, 2019

Numbers in an interval

Write a program that reads two numbers a and b, and prints all numbers between a and b.

Input: Input consists of two natural numbers a and b.

Output: Print a line with a, a+1,…, b−1, b. Separate the numbers with commas.

#include <iostream>
using namespace std;

int main () {
    
    int x, y;
    cin >> x >> y;
    bool primera=true;
    for (int i =x; i<=y; ++i) {
        if (primera) primera=false;
        else cout << ',';
        cout << i;
    }
    cout << endl;
}


No comments:

Post a Comment

Modelo OSI

Open System Interconnection , Interconexión de Sistemas Abiertos, es un modelo para estudiar las categorías en que se pueden dividir los pr...