Toggle nth bit in a given integer - num
Answers were Sorted based on User's Feedback
Answer / sanyam jain
#include<stdio.h>
int main()
{
int a,b;
printf("Enter the number to be flipped\n");
scanf("%d",&a);
printf("Enter which bit to be flipped: ");
scanf("%d",&b);
a = a^(1<<(b-1));
printf("Resultan number is %d\n",a);
}
Is This Answer Correct ? | 6 Yes | 3 No |
Answer / banavathvishnu
#include<stdio.h>
#include<conio.h>
Togglebit(int k,int bit)
{
printf("after %d bit is toggled = %d",bit,(k^(1<<(bit-
1))));
return 1;
}
int main()
{
int i;
int bitno;
printf("enter the number \n");
scanf("%d",&i);
printf("enter the bit number to toggle \n");
scanf("%d",&bitno);
Togglebit(i,bitno);
getch();
return 1;
}
Is This Answer Correct ? | 1 Yes | 4 No |
write a program to arrange the contents of a 1D array in ascending order
define c
if function is declared as static in one source file, if I would like to use the same function in some other source file...is it possible....how ?
What do you mean by keywords in c?
the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none
Is a pointer a kind of array?
What is a scope resolution operator in c?
How can I read a directory in a C program?
2 Answers Bright Outdoor, Wipro,
What is the purpose of void pointer?
write a program that prints a pascal triangle based on the user input(like how many stages) in an efficient time and optimized code?
Write a program in c to print 1 121 12321 1234321 123454321
11 Answers ANR, College School Exams Tests, Mu Sigma, Wipro,
what is the output of the following program? #include<stdio.h> void main() { int x=4,y=3,z; z=x-- -y; printf("\n%d %d %d",x,y,z); }