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 |
main() { char p[] = "hello world!"; p = "vector"; printf("%s",p); }
2 Answers Vector, Vector India,
long int size a) 4 bytes b) 2 bytes c) compiler dependent d) 8 bytes
18 Answers Acropolis, HCL, Intel, TCS,
How can a process change an environment variable in its caller?
Are global variables static in c?
What is your stream meaning?
Is fortran still used today?
main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); }
Program to display given 3 integers in ascending order
When should you not use a type cast?
What are the general description for loop statement and available loop types in c?
main() { int l=6; switch(l) { default:l=l+2; case 4:l=4; case 5:l++; break; } printf("%d",l); }
Given an array of characters, how would you reverse it? How would you reverse it without using indexing in the array?