w3resource

C Exercises: Shift the specified data by two bits to the left

C Basic Declarations and Expressions: Exercise-56 with Solution

Write a C program to shift given data by two bits to the left.

Sample Solution:

C Code:

#include<stdio.h>
int main() {
    int a, b;

    // Prompt user to input an integer
    printf("Read the integer from keyboard-");
    scanf("%d",&a);

    // Display the original integer value
    printf("\nInteger value = %d ",a);

    // Left shift 'a' by 2 bits and assign it to 'b'
    a <<= 2;
    b = a;

    // Display the left shifted data
    printf("\nThe left shifted data is = %d ",b);

    return 0;
}

Sample Output:

Read the integer from keyboard-
Integer value = 2 
The left shifted data is = 8 

Flowchart:

C Programming Flowchart: Shift the specified data by two bits to the left

C programming Code Editor:

Previous: Write a C program that swaps two numbers without using third variable.
Next: Write a C program to reverse and print a given number.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/c-programming-exercises/basic-declarations-and-expressions/c-programming-basic-exercises-56.php