VOOZH about

URL: https://www.geeksforgeeks.org/c/write-a-c-program-to-print-geeks-for-geeks-without-using-a-semicolon/

⇱ Write a C program to print "Geeks for Geeks" without using a semicolon - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Write a C program to print "Geeks for Geeks" without using a semicolon

Last Updated : 11 Sep, 2023

First of all we have to understand how printf() function works. Prototype of printf() function is:

int printf( const char *format , ...)

Parameter

  • format: This is a string that contains a text to be written to stdout.
  • Additional arguments: ... (Three dots are called ellipses) which indicates the variable number of arguments depending upon the format string.

printf() returns the total number of characters written to stdout. Therefore it can be used as a condition check in an if condition, while condition, switch case and Macros. Let's see each of these conditions one by one.

  1. Using if condition: 

Time Complexity: O(1)
Auxiliary Space: O(1)

          2. Using while condition: 

Time Complexity: O(n)
Auxiliary Space: O(1)

           3. Using switch case: 

Time Complexity: O(1)
Auxiliary Space: O(1)

         4. Using Macros: 

Time Complexity: O(1)
Auxiliary Space: O(1)

Output: Geeks for Geeks

One trivial extension of the above problem: Write a C program to print ";" without using a semicolon 

Output: ;

Time Complexity: O(1)

Auxiliary Space: O(1)

This blog is contributed by Shubham Bansal.

Comment
Article Tags: