Hanwool Codes RSS Tag Admin Write Guestbook
전체 글 (45)
2023-01-22 18:00:34

Basic Data Types | HackerRank

 

Basic Data Types | HackerRank

Learn about the basic data types in C++. Take the given input and print them.

www.hackerrank.com

 

Goal

1. Read space-seprated values : int, long, char, float and double, respectively

2. Print each element on a new line in the same order it was received as input. + correct decimal points of floating and double points.

 

 

Solution

Follow HackerRank explanation of c++ data types and their format specifiers.

// Basic Data Types

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    // Complete the code.
    int a;
    long b;
    char c;
    float d;
    double e;

    scanf("%d %ld %c %f %lf", &a, &b, &c, &d, &e);
    printf("%d\n", a);
    printf("%ld\n", b);
    printf("%c\n", c);
    printf("%f\n", d);
    printf("%lf\n", e);
    return 0;
}
2023-01-21 18:00:25

Loops | HackerRank

 

Loops | HackerRank

Practice using "for" and "while" loops in Python.

www.hackerrank.com

 

Goal

 

Read integer value n, and print i² for all non-negative integer i < n.

 

 

Solution

If you know for statement in python, it woul be very easy task.

# Loops

if __name__ == '__main__':
    n = int(input())
    
    for i in range(n):
        print(i * i)
2023-01-20 18:00:20

Python: Division | HackerRank

 

Python: Division | HackerRank

Division using __future__ module.

www.hackerrank.com

 

Goal

 

1. Read two integers each line.

2. print (a//b) in first line.

3. print (a/b) in second line.

 

 

 

Solution

 

Use input() function to read two integer values. But don't forget to convert input return value into integer value. 

# Python: Division

if __name__ == '__main__':
    a = int(input())
    b = int(input())
    
    print(a // b)
    print(a / b)


Hanwool Codes. Designed by 코딩재개발.