BaşlayınÜcretsiz başlayın

Conversion between numbers using cast

Although there are several numeric data types available in C++, you only need to manipulate integers (int) and floating point numbers (double).

In the last exercise, you converted an integer to a double by appending .0 at the end. However, you can also use casting to change the data types.

Bu egzersiz, kursun bir parçasıdır

Optimizing R Code with Rcpp

Kursa Göz Atın

Egzersiz talimatları

  • Load the Rcpp package.
  • Evaluate 17 / 2 in C++ with evalCpp().
  • Cast 17 to a double and divide it by 2.
  • Cast 56.3 to an int.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

# Load Rcpp
___

# Evaluate 17 / 2 in C++
___

# Cast 17 to a double and divide by 2
___

# Cast 56.3 to an int
___
Kodu Düzenle ve Çalıştır