Program 2: Using * and /
Let's see another example to swap two numbers using * and /.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a=10, b=20;
printf("Before swap a=%d b=%d",a,b);
a=a*b;//a=200 (10*20)
b=a/b;//b=10 (200/20)
a=a/b;//a=20 (200/10)
system("cls");
printf("\nAfter swap a=%d b=%d",a,b);
return 0;
}
9) Print "hello" without using semicolon
We can print "hello" or "hello world" or anything else in C without using semicolon. There are various ways to do so:
-
Using if
-
Using switch
-
Using loop etc.
Write a c program to print "hello" without using semicolon
Program 1: Using if statement
Let's see a simple c example to print "hello world" using if statement and without using semicolon.
#include<stdio.h>
int main()
{
if(printf("hello world")){}
return 0;
}
Program 2: Using switch statement
Let's see a simple c example to print "hello world" using switch statement and without using semicolon.
#include<stdio.h>
int main()
{
switch(printf("hello world")){}
return 0;
}
Program 3: Using while loop
Let's see a simple c example to print "hello world" using while loop and without using semicolon.
#include<stdio.h>
int main()
{
while(!printf("hello world")){}
return 0;
}