< All Topics
Print

Write a C program to display Your Name, Address and City in different lines.

In this article, I will show you how to write a C program to display your name, address and city in different lines using a simple printf statement or puts statement. This is a basic program that can help you learn the syntax and structure of C language.

To display something on the screen, we can use the printf function, which is part of the standard input/output library (stdio.h). The printf function takes a string as an argument and prints it to the standard output device, which is usually the console or the terminal.

To display multiple lines of text, we can use the escape sequence \n, which represents a newline character. This tells the printf function to move the cursor to the next line before printing the rest of the string.

Steps

  • Include the stdio.h header file
  • Define the main function
  • Declare variables to store your name, address and city
  • Assign values to the variables using string literals
  • Use printf statements to display the variables in different lines
  • Return 0 from the main function

Full Code [using printf() statement]

To display your name, address and city in different lines, you can write a C program like this:

#include<stdio.h> // include the stdio.h library

int main() // define the main function
{
// use printf to display your name, address and city in different lines
printf("John De Costa\n");
printf("Down Town Lane\n");
printf("Montiago\n");

return 0; // return 0 to indicate successful execution

}

Output

John De Costa
Down Town Lane
Montiago

Full Code [using puts() statement]

To display your name, address and city in different lines, you can write a C program like this:

#include<stdio.h> // include the stdio.h library

int main() // define the main function
{
// use printf to display your name, address and city in different lines
puts("John De Costa");  // with puts there is no need to use \n for new-lne.
puts("Down Town Lane"); // every puts statement starts from new line.
printf("Montiago");

return 0; // return 0 to indicate successful execution

}

Output

John De Costa
Down Town Lane
Montiago

Conclusion

Congratulations! You have successfully written a C program to display your name, address and city in different lines using a simple printf statement puts statement. I hope you enjoyed this blog post and learned something new. If you have any questions or feedback, please leave a comment below.

Thank you for reading!

EzyLearning!! Happy Learning!!


Recommended Readings

Leave a comment

Table of Contents