C Program to print “hello” without semicolon

Configurare noua (How To)

Situatie

We can print “hello” or “hello world” or anything else in C without using semicolon. There are various ways to do so:

  1. Using if
  2. Using switch
  3. Using loop

Solutie

Pasi de urmat

Program 1: Using if statement

Let’s see a simple c example to print “hello world” using if statement and without using semicolon.

 

  1. #include<stdio.h>
  2.  int main()
  3. {
  4.  if(printf(“hello world”)){}
  5. return 0;
  6. }

Output:

hello world

Program 2: Using switch statement

Let’s see a simple c example to print “hello world” using switch statement and without using semicolon.

  1. #include<stdio.h>
  2.  int main()
  3. {
  4. switch(printf(“hello world”)){}
  5. return 0;
  6. }

Output:

hello world

 

Program 3: Using while loop

Let’s see a simple c example to print “hello world” using while loop and without using semicolon.

  1. #include<stdio.h>
  2.  int main()
  3. {
  4.    while(!printf(“hello world”)){}
  5. return 0;
  6. }

Output:

hello world

Tip solutie

Permanent

Voteaza

(11 din 41 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?