You are on page 1of 6

C Program to Print HELLO without HELLO

Here we are going to print HELLO without using any of the later from the HELLO, anywhere in
the programing. Just think before proceeding further how we can do this..

Well here is the answer; here we are using ASCII CODE of the character to print HELLO.

ASCII TABLE OF ALPHABETS

Code:

//C program to print HELLO without HELLO


#include<stdio.h>
#include<conio.h>
void main()
{
int a=72,b=69,c=76,d=79;
printf(%c%c%c%c%c,a,b,c,c,d);
getch();
}
-
Logic of the code:

first you give a try to find the logic..

Here in the code we took integer as data type and given ASCII code of H to a, E to b, L to c and
O to d.

Step by step compiler start compiling (saving the code). First it comes to data type. It is int then
it comes to printf where Format Specifier of Data Type is CHARCHTER (%C).

Compiler compiling program as integer form where a=72, b=69, c=76, d=79 and when it comes
to output part the Format Specifier is character so it converting 72 (number) to character form
and hence we get 72 as H and so on..

C Program for Multiplication without Using Multiply


Operator *
Here is another program from the series tricky code. Here I am going to show you how we can
do Multiplication without using Multiply Operator *. Programs like this you will rarely get
anywhere else.

Comment below to express your feeling and suggest me new idea for more tricky code.

Logic of the code:

First you give a try to think the logic.

Here is the answer,

Let a and b are two variables then c=axb. We take 9 as a and 8 as b then c=72.

In other word we are adding 9, 8 times or adding 9, 8 times, so simple logic. This is what I
converted into programing.

Code:

//C Program for Multiplication without Using Multiply Operator *


#include<stdio.h>
#include<conio.h>
void main()
{
int n,m,s=0;
clrscr();
printf(\nEnter the values);
scanf(%d%d,&n,&m);
while(m!=0)
{
s=s+n;
m;
}
printf(Result = %d,s);
getch();

C++ Program to Convert Digits to its Equivalent Words


Here is another tricky code, where we can Convert Digits to its Equivalent Words.

the program work till 5 digits of number

suppose the Input is: 12345

then the Output will be: OneTwoThreeFourFive

code:

//C++ Program to Convert Digits to its Equivalent Words


#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],i,n;
clrscr();
cout<<Enter the Value;
cin>>n;
for(i=4;i>=0;i)
{
a[i]=n%10;
n=n/10;
}
for(i=0;i<5;i++)
{
if(a[i]!=0)
{
switch(a[i])
{
case 0:cout<<Zero;
break;
case 1:cout<<One;
break;
case 2:cout<<Two;
break;
case 3:cout<<Three;
break;
case 4:cout<<Four;
break;
case 5:cout<<Five;
break;
case 6:cout<<Six;
break;
case 7:cout<<Seven;
break;
case 8:cout<<Eight;
break;
case 9:cout<<Nine;
break;
}
}
}
getch();

Writing a C program without a main()


C
Programming
Hack

This post is a simple example of deception. It shows how a programmer can defy the very
important rule of having a main() in c program and still make the program run. This illustrates
the concept on a simple program though it can be scaled to much bigger and more complex
programs.

#include<stdio.h>
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)

int begin()

{
printf( hello );
}

This program runs without main().

how??

Here we are using preprocessor(a program which processes the source code before compilation.)
directive #define with arguments to give an impression that the program runs without main. But
in reality it runs with a hidden main function.

The ## operator is called the token pasting or token merging operator. That is we can merge
two or more characters with it.

In the 2nd line of the program-


#define decode(s,t,u,m,p,e,d) m##s##u##t

What is the preprocessor doing here. The macro decode(s,t,u,m,p,e,d) is being expanded as
msut (The ## operator merges m,s,u & t into msut). The logic is when you pass (s,t,u,m,p,e,d)
as argument it merges the 4th,1st,3rd & the 2nd characters(tokens)

Now look at the third line of the program

#define begin decode(a,n,i,m,a,t,e)

Here the preprocessor replaces the macro begin with the expansion decode(a,n,i,m,a,t,e).
According to the macro definition in the previous line the argument must be expanded so that the
4th,1st,3rd & the 2nd characters must be merged. In the argument (a,n,i,m,a,t,e) 4th,1st,3rd & the
2nd characters are m,a,i & n.

So the third line int begin is replaced by int main by the preprocessor before the program is
passed on for the compiler. Thats it

So actually C program can never run without a main() . We are just disguising the main() with
the preprocessor, but actually there exists a hidden main function in the program.

We all know working of for loop but it can be used to minimize the size of the program for
example :

SYNTAX: for(initialization;condition;increment or decrements)

Initialization part : It works only one once.

Condition part: it works every time when the loop is for increment or decremented.

Increment or decrements part:this part is used for incriminating or decrementing variables. in


other words for loop can be used to solve the program in a single line. consider the following
part of the program :

To find the reverse of a number :

ex: input: 42139 output :93124

*PROGRAM *

{
int a,s;
for( scanf("%d",&a) , s=0 ; a!=0 ; s=s*10+(a%10) ,
a=a/10) ;
printf("%d",s);
}

In the above program finding reverse of a number is done in a single step.

Explanation: the initialization part always works once thus we are getting input in that part and
also initializing the variable once this also takes place once then comes to condition part it
always checks condition thus condition is checked there then further in increment and
decrements part can not only used to manipulate but can also be used for some other process like
i used in the above program by using (,) we can do the step one after other Let me explain u
better with another good example:

A program to find the length of the string can be done in single line using for loop:

INPUT:: rangeesh OUTPUT::8

PROGRAM

{
char name[100];
for(int i=0,scanf("%s",name);name[i]!='\0';i++);
printf("%d",i);
}

it works the same way which i explained above, thus for loop can be used by the programmers
for the efficient use of the memory space in C.

NOTE: the above logic works for C i have tested it and then only explained here.I don't know
about other languages,that is whether this trick works or not.

You might also like