Anda di halaman 1dari 6

Printf Hello word in C without using semicolon [only ones ]

#include<stdio.h>
void main()
{
if(printf("Hello"))
{
}
}

Printf Hello word in C without using semicolon [infinite times]

#include<stdio.h>
void main()
{
while(printf("Hello"))
{
}
}

Printf Hello [Using Switch]

#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

This can be achieved in 3 ways :


1. Using Printf Statement 10 Times.
2. Using Recursive Function
3. Using goto Statement.
4. Recursive Main Function

Printf Statement 10 times


#include<stdio.h>
void main()
{
printf("1");
printf("2");
printf("3");
printf("4");
printf("5");
printf("6");
printf("7");
printf("8");
printf("9");
printf("10");
}
Recursive Function

#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);
}

Recursive function : Calling Itself .

printNumber function calls itself so it is called Recursive function .

Using Goto Statement

#include<stdio.h>
void main() {
int i = 0;
Start: i = i + 1;
printf("%d", i);
if (i <= 10)
goto Start;
}

Using Recursive Main

#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

C Program to Add two numbers without using arithmetic Operators


Using Recursive Function

#include<stdio.h>
int add(int, int);
int main() {
int num1, num2;

printf("\nEnter the two Numbers : ");


scanf("%d %d", &num1, &num2);
printf("\nAddition of two num is : %d", add(num1, num2));
return (0);
}
int add(int num1, int num2) {
if (!num1)
return num2;
else
return add((num1 & num2) << 1, num1 ^ num2);
}
Using While Loop

#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>

int sum(int, int);


int main() {
int a, b;
printf("Enter the two Numbers: ");
scanf("%d %d", &a, &b);
printf("Addition of two num. is : %d", add(a, b));
return(0);
}
int add(int num1, int num2) {
int i;
for (i = 0; i < num2; i++)
num1++;
return num1;
}
Using Subtraction

#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

3. So printf will return total length of string


4. It returns 26 to outer printf
5. This outer printf will print 26

Anda mungkin juga menyukai