1 to 100 – Hyphen Separated

The program must print from 1 to 100 with the values separated by a hyphen.

Python

print('-'.join([str(ctr) for ctr in range(1, 101)]))

Java

import java.util.*;
public class Hello {
    public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
System.out.print(num1 - num2);
}
}

C

#include <stdlib.h>
#include  <stdio.h>
int main()
{
    int ctr;
    for(ctr = 1; ctr < 100; ctr++)
    {
        printf("%d-", ctr);
    }
    printf("%d", ctr);
    return 0;
}

C++

#include <iostream>
using namespace std;
int main()
{
    int ctr;
    for(ctr = 1; ctr < 100; ctr++)
    {
        cout << ctr << '-';
    }
    cout << ctr;
    return 0;
}
Previous Article

One to Five - Words

Next Article

Print - 1 to 222

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨