converter_2nd.c - #include <stdio.h>#include <math.h> int dbinary(int given int remainder,ans = 0,counter for(counter = 0;given!=0 counter remainder =

converter_2nd.c - #include <stdio.h>#include <math.h> int...

This preview shows page 1 - 2 out of 2 pages.

#include <stdio.h> #include <math.h> int dbinary(int given) { int remainder,ans = 0,counter; for (counter = 0;given !=0;++counter){ remainder = given % 2; ans = ans + (remainder)*(pow(10,counter)); given = given / 2; } return ans; } int bdecimal(int given) { int remainder,ans = 0,counter; for (counter = 0;given !=0;++counter){ remainder = given % 10; ans = ans + (remainder)*(pow(2,counter)); given = given /10; } return ans; } int odecimal(int given) { int remainder,ans = 0,counter; for (counter = 0;given !=0;++counter){ remainder = given % 10; ans = ans + (remainder)*(pow(8,counter)); given = given /10; } return ans; } int main() { int given,t; printf("**********************************************\n"); printf("* Please choose your given number *"); printf("\n**********************************************"); printf("\n* Type number 2 for Binary *"); printf("\n* Type number 8 for Octal *"); printf("\n* Type number 10 for Decimal *"); printf("\n**********************************************\n"); printf("* INPUT *"); printf("\n**********************************************"); printf("\n\nEnter the given type here: "); scanf("%d",&t); printf("Enter given number here: ");
Image of page 1

Subscribe to view the full document.

Image of page 2

Unformatted text preview: scanf(&quot;%d&quot;, &amp;given); printf(&quot;\n**********************************************\n&quot;); printf(&quot;* CONVERTION *&quot;); printf(&quot;\n**********************************************\n&quot;); if (t == 10){ printf(&quot;\nThe value of decimal number %d in binary is: %d&quot;,given,dbinary(given)); printf(&quot;\nThe value of decimal number %d in octal is: %o&quot;,given,given); printf(&quot;\nThe value of decimal number %d in hexadecimal is: %x&quot;,given,given); } else if (t == 8){ printf(&quot;\nThe value of octal number %d in binary is: %d&quot;,given,dbinary(odecimal(given))); printf(&quot;\nThe value of octal number %d in decimal is: %d&quot;,given,odecimal(given)); printf(&quot;\nThe value of octal number %d in hexadecimal is: %x&quot;,given,odecimal(given)); } else if (t == 2){ printf(&quot;\nThe value of binary number %d in decimal is: %d&quot;,given,bdecimal(given)); printf(&quot;\nThe value of binary number %d in octal is: %o&quot;,given,bdecimal(given)); printf(&quot;\nThe value of binary number %din hexadecimal is: %x&quot;,given,bdecimal(given)); } else printf(&quot;\nInvalid type of inputs!!!&quot;); printf(&quot;\n\n**********************************************&quot;); }...
View Full Document

  • Fall '18

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes