Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C Programming In C, (not C++) write a \"HelloWorld\" program. Use the nano edito

ID: 3677245 • Letter: C

Question

C Programming

In C, (not C++) write a "HelloWorld" program. Use the nano editor (or gedit) program to create the source file in your home directory. To compile the source file:
To compile your helloworld.c file type:
   gcc   helloworld.c    -ohelloworld.exe
fix any errors that the compiler may detect by editing the source file. When everything is OK (i.e. no errors) run your program by typing:    
./helloworld.exe
Don’t forget the ./ in front of it.

Continue to write a short program (in a separate file) that will allow the user to enter an integer from 0 to 32) and will print out the binary equivalent (a string of 1’s and 0’s that represent that binary number. (This doesn't require any arrays or division). Name the program "PrintBinary".

Explanation / Answer

#include "printBinary.h"
#include<iostream>
HelloWorld.c

#include <stdio.h>
#include <conio.h>

int main()
{
   printf ("Hello, world !");
   getch();
   return 0;
}

run.bat

printBinary.c


using namespace std;

#define PR(STR, EXPR)
    cout << STR; printBinary(EXPR); cout << endl;

int main() {
    unsigned int getval;
    unsigned char a, b;
    cout << "Enter a number between 0 and 255: ";
    cin >> getval; a = getval;
    PR("a in binary: ", a);
    cout << "Enter a number between 0 and 255: ";
    cin >> getval; b = getval;
    PR("b in binary: ", b);
    PR("a | b = ", a | b);
    PR("a & b = ", a & b);
    PR("a ^ b = ", a ^ b);
    PR("~a = ", ~a);
    PR("~b = ", ~b);
  
    unsigned char c = 0x5A;
    PR("c in binary: ", c);
    a |= c;
    PR("a |= c; a = ", a);
    b &= c;
    PR("b &= c; b = ", b);
    b ^= a;
    PR("b ^= a; b = ", b);
}