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

Print to the console

You can use Rprintf() to print formatted output to the console. It is similar to the sprintf() function in R, and uses the format specifiers:

  • %d to specify an integer
  • %s to specify a string

Bu egzersiz

Optimizing R Code with Rcpp

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

Write a function that adds two integers (x and y) and prints the following message about it:

** <x> + <y> = <x + y>

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Define the function add()
cppFunction('
  int add(int x, int y) {
    int res = x + y ;
    ___("** %d + ___ = ___\\n", x, y, res) ;
    return res ;
  }
')

# Call add() to print THE answer
add(40, 2)
Kodu Düzenle ve Çalıştır