Multiply Any Number with 9, 10 without using * / % Operator in C

#include "stdafx.h"
#include "conio.h"

#include <stdio.h>
#define MULBY10(x) ((x<<4) - (x<<2) - (x<<1))
#define MULBY9(x) ((x<<3) + x)
#define MULBY5(x) ((x<<2) + x)
#define MULBY50(x) ((x<<5) + (x<<4) + (x<<1))
#define MULBY100(x) ((x<<6) + (x<<5) + (x<<2))
#define MULBY200(x) ((x<<7) + (x<<6) + (x<<3))
#define MULBY1024(x) (x<<10)

int _tmain()
{
    printf("Hello, World!\n");
    
    int a = 10;
    printf("%d\n",MULBY10(a));
    printf("%d\n",MULBY9(a));
    printf("%d\n",MULBY5(a));
    printf("%d\n",MULBY50(a));
    printf("%d\n",MULBY100(a));
    printf("%d\n",MULBY200(a));
    printf("%d\n",MULBY1024(a));
    getch();
    return 0;
}

OutPut:
Hello, World!
100
90
50
500
1000
2000
10240

Related Post:


Removing Space from Given String & Different Methods to Count Number of Ones in Given Value

Booting Sequence for Boot Process in Linux

How to count number of 1 or set bits in a given number

What is Segmentation fault ?

How to Access Private Data Members in C++ without using friend function

Process Vs Thread 

How to Add Two Numbers Without Using + Operator in C 

Overview of Function Pointer in C with Example - What is function pointer & how to use it

How to Fork child process with waitpid & execl in linux with c example code

Share on Google Plus

About Kapil Thakar

"I am Kapil Thakar, an Embedded Engineer cum Blogger wants to learn new things. I love to share my knowledge solutions to the problems. Interested in Blogging, Creative-Writing, SEO, Website Creation, Video Making, Editing, Affiliation Programs, Online Making Money."
    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment

Related Posts Plugin for WordPress, Blogger...