Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

write a c program to change only the 3rd bit of the
particular number such that other bits are not affected..
if bitnum=10(say.. it can be any no..

Answer Posted / kishore batta

#include<stdio.h>
int main()
{
int number=0,set_bit=0,result=0;
printf("Enter the number:");
scanf("%x",&number);
printf("which bit to be set?:");
scanf("%x",&set_bit);
result=number|(0x1<<(set_bit-1));
printf("After setting the bit, the result is:%x
",result);
return 0;
}
OUTPUT:
Enter the number:1
which bit to be set?:4
After setting the bit, the result is:9

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is difference between structure and union with example?

990


what are the different storage classes in c?

1120


What is c language and why we use it?

1004


Why is c called a structured programming language?

1214


How to throw some light on the b tree?

1021


Which type of language is c?

1021


please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code

2131


What is type qualifiers?

1079


Is there a way to compare two structure variables?

1058


write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays

2186


Can a program have two main functions?

1061


Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)

1099


What is the condition that is applied with ?: Operator?

1070


how is the examination pattern?

1965


Can two or more operators such as and be combined in a single line of program code?

1310