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 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")
                        
                        

🖥 Program 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"
> 
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.