#include<stdio.h>
void main()
{
if(printf("Hello"))
{
}
}
#include<stdio.h>
void main()
{
while(printf("Hello"))
{
}
}
#include<stdio.h>
void main()
{
switch(printf("Hello"))
{
}
}
Using Else-if Ladder
#include<stdio.h>
void main()
{
if(printf(""))
{
}
else if (printf("Hello"))
{
}
else
{
}
}
Printf Hello [Using While and Not]
#include<stdio.h>
void main()
{
while(!printf("Hello"))
{
}
}
Using #define
#include<stdio.h>
#define PRINT printf("Hello")
void main()
{
if(PRINT)
{
}
}
Print 1-10 numbers without using Conditional Loop i.e without using
for Loop
while Loop
do-while Loop
#include<stdio.h>
void printNumber(int value) {
int i;
printf("%d\n", value);
i = value + 1;
if (i > 10)
return;
printNumber(i);
}
void main() {
printNumber(1);
}
#include<stdio.h>
void main() {
int i = 0;
Start: i = i + 1;
printf("%d", i);
if (i <= 10)
goto Start;
}
#include<stdio.h>
void main() {
static int i = 1;
if (i <= 10) {
printf("%d", i++);
main();
}
}
Static variable inside a function means once the variable has been initialized, it
remains in memory until the end of the program
#include<stdio.h>
int add(int, int);
int main() {
int num1, num2;
#include<stdio.h>
int main() {
int num1 = 10, num2 = 5, i;
while (num2 > 0) {
num1++;
num2--;
}
printf("%d", num1);
return (0);
}
Using While Loop
#include<stdio.h>
int main() {
int num1 = 10, num2 = 5, i;
while (num2--) {
num1++;
}
printf("Sum is : %d", num1);
return (0);
}
Using For Loop
#include<stdio.h>
#include<stdio.h>
int main() {
int num1 = 10, num2 = 5;
num1 = num1 - (-num2);
printf("Sum is : %d",num1);
return (0);
}
nested Printf statements
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
printf("%d", printf("abcdefghijklmnopqrstuvwxyz"));
getch();
}
Output :
abcdefghijklmnopqrstuvwxyz26
How ?
1. abcdefghijklmnopqrstuvwxyz will be first Printed while executing inner printf
2. Total Length of the abcdefghijklmnopqrstuvwxyz is 26