[Programming] Question 12: Demonstrate multiplication by powers of 2 using left shift operator in C?

 

#include <stdio.h>

int main() {
	int num = 5;

	printf("Original number: %d\n", num);

	num = num << 3; // Multiply by 2^3 = 8

	printf("After multiplication by 8: %d\n", num);

	return 0;
} 

Inside the main() function:

- An integer variable num is initialized with the value 5.

- The original value of num is printed to the console.

- The num variable is left shifted by 3 bits using the `<<` operator, effectively multiplying it by 8 (2^3).

- The result after multiplication is printed to the console.



You might like

Loading data...

Featured Posts

Machine Learning Technologies

Introduction to Machine Learning Technologies Machine Learning (ML) is a branch of artificial intelligence (AI) that enables systems to le...

Popular Posts