Skip to main content
·3 min read

C Bits - Getting Started

The 1st part in a mini-series for beginners in C. Hello. Hello. Hello. It’s been a while, but no worries. Once again, I’m here to make programming a little easi

C Bits - Getting Started

The 1st part in a mini-series for beginners in C.

Hello. Hello. Hello.

It’s been a while, but no worries. Once again, I’m here to make programming a little easier by providing the literal solutions…I’ve decided to use better resources so that my programs can be more easily shared. The obvious solution of course was to use GitHub – git it?!Any who, here I will provide the questions and then you can go to the necessary GitHub repository that I uploaded and download the program files - yay! :DThe solutions that also include the question as a comment on top and can be found on my GitHub.

Problem 1.1 - Compute division

Why is the result 0.000? Please fix it.#include

float answer; /The result of our calculation/

int main() {

answer = 1/8;

printf("The value of 1/8 is %f\n", answer);

return 0;

}

Problem 1.2 - Wrong output

Why does the program print The answer is –1073745604? Values will vary. Please fix it, so it displays the correct result.#include

int answer; /The result of our calculation/

int main() {

answer = 3 + 9;

printf("The answer is %d\n");

return 0;

}

Problem 1.3 - A compile error

You will get compiler errors, when you try to compile the given code example below. Read the error messages that the compiler produces and fix the errors, so your source code compiles sucessfully. Then fix the program to print the correct result.#include

float result; /* The result of the division */

int main() {

result = 6/23.0;

printf("The result is %d\n", result);

return 0;

}

Problem 1.4 - Simple arithmetics

Write a program that:

  • assigns 13 to a and 9 to b - computes the sum of a and b and prints the result - computes the product of a and b and prints the result 4. computes the difference of a and b and prints the result 5. computes the division of a and b and prints the result (the result should be a float) 6. computes the remainder of the division of a and b and prints the result 7. prints the values of a and b

Problem 1.5 - Using printf for multiple data types and conversions

Write a program that:

  • declares and initializes an integer variable a with 123, and prints the value of a over 7 places - declares and initializes an float variable b with −89.6548754, and prints the value of b over 10 places and with a floating point precision of - declares and initializes a char variable c with ‘b’, and prints the character on the screen 4. declares and initializes a double variable d with 19.987243, and prints the value of d with a floating point precision of 2

Problem 1.6 - Printing a char as character and as decimal value

Write a program that:

  • declares and initializes a char variable letter with ‘a’ and prints it on the screen as a character and as corresponding ASCII code - declares and initializes an integer variable a with 123, and prints the value of a over 7 place - declares and initializes a char variable letter with ‘a’ and prints it on the screen as a character and as corresponding ASCII code

Tags 🏷️

Stay in the loop

🦄 The Unicorn Engineer ✨

Personal and career learnings, advice, collaboration opportunities, and more. Delivered straight to your inbox.

No spam. Unsubscribe anytime.

Keep Reading

Related Posts

C Bits - Speeding Up A Bit
·2 min read

C Bits - Speeding Up A Bit

The 2nd part in a mini-series for beginners in C. 🚤 Hello. Hello. Hello So once again, I’m here to make programming a little easier by providing the literal so

Blog
C++ Bits - Array Manipulation
·4 min read

C++ Bits - Array Manipulation

Manipulating arrays in C++. ✂️ Purpose To do real simpleton array manipulation. To use functions with awkward arrays. - Write a C++ program to read numbers usin

Blog
C++ Bits - Clothing Sizes
·4 min read

C++ Bits - Clothing Sizes

Testing out clothes in C++. 🚺 Purpose To declare weight, height, hat size, jacket size, and waist size. - Write a C++ program to calculate a person’s hat size,

Blog

Stay in the Loop ✍🏽

I share thoughts on engineering, career growth, and the tech industry. Follow along for more.