Home / Programs / Write a function which will print the name of a person along with a hello message, like Hello Person Name
Programming Example

Write a function which will print the name of a person along with a hello message, like Hello Person Name

👁 731 Views
💻 Practical Program
📘 Step by Step Learning
Write a function which will print the name of a person along with a hello message, like Hello Person Name

Program Code

# Below is our function 

hello.person <- function(name)
{
  sprintf("Hello %s", name)
}

# to invoke the function, call the function
hello.person("Rumman")
                        

Output

[1] "Hello Rumman"

Explanation

This is a user defined function using R programming Language. Another way to do that.
hello.person <- function(firstName, lastName)
{
  print(sprintf("Hello %s %s", firstName, lastName))
}

hello.person("Rumman", "Ansari")

hello.person(lastName = "Ansari", firstName = "Rumman")

If you will run the above program you will get the following result

> hello.person("Rumman", "Ansari")
[1] "Hello Rumman Ansari"
> hello.person(lastName = "Ansari", firstName = "Rumman")
[1] "Hello Rumman Ansari"
> 

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.