First off, that's not C#, it's C - they may look similar, but they are very, very different languages! Tagging your questions with the wrong languages can mean you wait a lot longer for a reply ...
Second, indent your code! It makes it a whole lot easier to read:
#include<stdio.h>
int main()
{
int num,N,M,K;
printf("Enter a number:");
scanf("%d",&num);
printf("Enter 'N':");
scanf("%d", &N);
num=num>>(N-1);
if((num&1)!=0)
{
printf("Enter 'M': ");
scanf("%d", &M);
K = num & ~(1 << M);
printf("Updated value of num is %d \n", K);
}
return 0;
}
It's less relevant with trivial fragmente like this, but get into the habit early and it can save you hours of frustration later.
Third, when you post a question, you need to explain what problem you have met: we have no idea what values you entered, or what happened when you did - so we have to guess and that may not address the problem you have found at all!
Start here:
Asking questions is a skill[
^] and think about what you need to know, and what you need to tell us in order to get help.
Do note that when you try to check if the Nth bit of
num
is set, you overwrite the existing value - which means you cannot complete the task as you don't have the original value entered by the user any more!
Instead of shifting
num
at all, I'd shift
1
N places to the left and AND that with num to check if it is set.