Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- /**
- * A programme demonstrates using bitwise operators for multiplication
- * Tested using Code::Blocks and Windows 7 Professional SP1
- *
- * @Author: Shaun B
- * @Version: 1.0.0.1 - 2012-09-13
- * @Todo:
- *
- **/
- static int a=0;
- static int times[12];
- int main();
- int main()
- {
- system("cls");
- printf("Demonstration of using bitwise operators to multiply whole numbers.\n\n");
- printf("Please enter a number\n");
- printf("C:\\>");
- scanf("%d",&a);
- times[ 0]= 0;
- times[ 1]= a; /**Times 1*/
- times[ 2]= a<<1; /**Times 2*/
- times[ 3]= (a<<1)+a; /**Times 3*/
- times[ 4]= a<<2; /**Times 4*/
- times[ 5]= (a<<2)+a; /**Times 5*/
- times[ 6]= (a<<2)+(a<<1); /**Times 6*/
- times[ 7]= (a<<2)+(a<<1)+(a); /**Times 7*/
- times[ 8]= a<<3; /**Times 8*/
- times[ 9]= (a<<3)+(a); /**Times 9*/
- times[10]= (a<<3)+(a<<1); /**Times 10*/
- times[11]= (a<<3)+(a<<1)+(a); /**Times 11*/
- times[12]= (a<<3)+(a<<2); /**Times 12*/
- for(int i=0; i<=12; i++)
- {
- printf("%4d x %4d = %10d\n", a, i, times[i]);
- }
- printf("\nPress the any key to end demonstration...");
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement