C program to convert Decimal number to binary

convert Decimal number to binary

Hello guys kaise ho ummid karta hu acche hi hoge aaj ke is artical mai hu aapko batayenge ki kaise c programming ke program ke through hum decimal number ko binary numbe mai convert kar sakta hai.

C program to convert number Decimal to binary

#include <stdio.h>

int main()

{

int n, c, k;

printf("Enter an integer in decimal number system\n");

scanf("%d", &n);

printf("%d in binary number system is:\n", n);

for (c = 31; c >= 0; c--)

{

 k = n >> c;

 if (k & 1)

 printf("1");

 else

 printf("0");

 }

 printf("\n");

 return 0;

 }

is program ko apne turbo c++ software mai type karne ke baad aap badi aasani se apne kisi bhi decimal number ko Binary number mai convert kar sakte ho is artical mai ye bataya gya ki kaise for loop ki help se badi aasani se is program ko banaya gaya hai is program mai humne simple 3 variable liye hai n,c,k aap in variable ki jagah chaho to appne bhi koi bhi variable rakh sakte ho fir humne printf function ki sahayata se User ko ek messege show karaya aap chaho to apna koi bhi messege user ko diplay kra sakte ho uske baad humne user se n naam ke variable mai ek decimal number liya decimal number lene ke baad humne usme for loop ka use kiya hai for loop mai humne ye bataya ki c=33 hai aur c>=0 ye condition rakhi aur c ki value mai umne ek ek decrement kar diya iske baad for loop mai humne bitwise oprator ka use karke k=n>>c initialize kiya ab humne for loop mai if else statment ki help se usmne condition rakhi hai

if (k & 1)

printf(“1”);

else

printf(“0”);

print ho uske baad simple loop se bahar nikalne ke baad printf(“\n”) iska use humne new line mai aane ke liye kiya fir last mai har program ki tarah joki humne iska suruaat mai main function ke saath iska return type rakha tha to last mai mai hum isko return (0) kara dete hai agar hum is program mai agar suruaat mai main main funtion ke saath void ka use karte to humko simple ek header file #include<conio.h> ka use karna hota aur last mai ek function ka use karna hota getch();  getch ka use hum screen ko hold karane ke liye karte hai ye kuch jarrori steps thi jinko follow karne ke baad ummid karta hu ki aap acche se samajh gaye hoge hi kaise hamara ye program work karta hai aur aap bhi is artical ko read karne ke baad badi aasani se is program ko banana sikh gaye hoge aur poori tarah se ye samajh gaye hoge ki ye program work kaise karta hai is artical ko read karne ke baad aap chaho to bina dekhe is program ko khud bna sakte ho.

agar aapko hamara ye Artical accha lga ho to aap ise apne friends ke saath bhi share kar sakte ho agar aapke dimaag mai koi question hai to aap hame niche comment box mai messege bhi kar sakte ho hum aapko jald se jald reply dene ki poori kosis karenge.

Please shere this post…

You Might Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *