Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-13-2019, 03:34 PM   #151
Andy Alt
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Debian64 stable, LFS 7.1
Posts: 434

Rep: Reputation: 91

2 to the power of 31 (2 to the 31st power). See Exponentiation (@jpollard touched upon it earlier).
2 members found this post helpful.
Old Yesterday, 10:51 PM   #152
Senior Member
Registered: Mar 2009
Location: Earth? I would say I hope so but I'm not so sure about that... I could just be a figment of your imagination too.
Distribution: CentOS at the time of this writing, but some others over the years too...
Posts: 2,316

Original Poster
Rep: Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041
Thanks again guys!

I've been reading the "Chapter 4 Variables, Data Types, and Arithmetic Expressions" and a lot of it does make enough sense now, but there are a few things I'm not too sure about. I done the exercises I could, but the last ones I'm not really too sure about.

When it says something like "1.7e4", which according to the C pdf is scientific notation; does the "e" mean "exponent" ?

BTW RT, the typo in your post #136, about floating point numbers, I fixed. But I kept forgetting to mention before that I saw that before you corrected it, and fixed it.

#include <stdio.h>

int main(void)
   int a = 1;
   float b = 1;
   int test_int_result;
   float test_float_result;

   test_int_result = a / 2;
   test_float_result = b / 2;

   printf("Test result of dividing an integer by 2: %d / 2 = %d\n", a, test_int_result);
   printf("Test result of dividing a float by 2: %.01f / 2 = %.01f\n", b, test_float_result);

return 0;

/* The error I got when I forgot to add the "#include <stdio.h>" header below:
 * [james@jamespc math-helpers]$ gcc -Wall -Werror floating_point_numbers.c -o floating_point_numbers 
floating_point_numbers.c: In function ‘main’:
floating_point_numbers.c:12:4: error: implicit declaration of function ‘printf’ [-Werror=implicit-function-declaration]
    printf("Test result of dividing an integer by 2: %d / 2 = %d\n", a, test_int_result);
floating_point_numbers.c:12:4: error: incompatible implicit declaration of built-in function ‘printf’ [-Werror]
cc1: all warnings being treated as errors
Chapter 4 Exercises

(I haven't included some of the details below, because the post is long enough as it is.)

2. Which of the following are invalid variable names? Why?
6_05, _1312 - because you cannot use numbers (digits) in variable names.

_ - because there should be something after this.

3. Which of the following are invalid constants? Why?
0X0G1, 0XABCDEFL - because hexadecimals only go from A to F.

0x10.5 - because the dot is not a valid hexadecimal character.

15,000 - because you cannot use commas in constants, it would have to written as 15000 without the comma.

4. Write a program that converts 27° from degrees Fahrenheit (F) to degrees Celsius
(C) using the following formula:

C = (F - 32) / 1.8
#include <stdio.h>

int main(void)
int F = 27;
float C = (F - 32) / 1.8;

printf("Fahrenheit (F) to degrees Celsius: %f\n", C);

return 0;
5. What output would you expect from the following program?
It would display the character (char) "d" on the screen.

6. Write a program to evaluate the polynomial shown here:

3 2
3x - 5x + 6

for x = 2.55.
I'm not sure what the "3x" with the little "3" above it, and the "5x" with the little "2" above it mean? Also, I have no idea what "for x = 2.55." means.

7.Write a program that evaluates the following expression and displays the results
(remember to use exponential format to display the result):
(3.31 x 10-8 x 2.01 x 10-7) / (7.16 x 10-6 + 2.01 x 10-8)
Not sure what the little "-8" and "-7" mean? The "x" means multiply, doesn't it? I tried to read that link in post #151, but it doesn't make much sense to me, sorry.

8.To round off an integer i to the next largest even multiple of another integer j,
the following formula can be used:

Next_multiple = i + j - i % j

For example, to round off 256 days to the next largest number of days evenly
divisible by a week, values of i = 256 and j = 7 can be substituted into the pre-
ceding formula as follows:


= 256 + 7 - 256 % 7
= 256 + 7 - 4
= 259

Write a program to find the next largest even multiple for the following values of i and j:

i j
365 7
12,258 23
996 4
I'm really not sure about this one(s) ?

Like I said before, I tried to do as much as I could, but I really am not sure about the last couple of questions apart from what's obvious.
Old Today, 07:49 AM   #153
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 7,313
Blog Entries: 12

Rep: Reputation: 2813Reputation: 2813Reputation: 2813Reputation: 2813Reputation: 2813Reputation: 2813Reputation: 2813Reputation: 2813Reputation: 2813Reputation: 2813Reputation: 2813
1.) Most of your problems are understanding exponents. Research that topic more. The link offered by Andy Alt is excellent and 100% on the mark. If you have trouble with the topic, then web search for more resources that can explain it in ways which are easier for you to understand.

2.) I wouldn't get too hung up on recognizing good vs. bad variable names. The compiler will flag an error when you've used an illegal name.

- Interpreting a lengthy list of compiler warnings and errors can be an exercise in detective work.
- There are some really bad things a programmer can do, such as to use a C keyword as a variable.
- For instance, what if you named a variable "if", or "switch", or "float"?
- These are all special terms which mean something as part of control flow.
- You can't use them as variables, and the compiler will complain about them.
- But the error may not be exactly "You can't use 'switch' as a variable!"
- The error may say something like, "missing '(' identifier before 'switch'", or something like that.
- Eventually you'll realize that the use of 'switch' as a variable name is not allowed.
3.) % is the C modulus operator. Look it up, look up examples. And really. Because if you have difficulties with the 5-10 word description, that's about what I'd reiterate here, so that's not going to help. Read the description, and look at examples, then re-read the description, or other descriptions, and look at more examples. It's not rocket science, it is a rule applied to calculations. Once you learn it, you learn it. Until you do, you won't understand what code using that operator is doing.
2 members found this post helpful.


c programming, learning c

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Finally decided to try to get libinput to work Timothy Miller Linux - Hardware 3 01-04-2018 09:04 PM
Decided to try Lubuntu 14.04 on my netbook... pcninja Ubuntu 4 04-20-2014 09:18 PM
Finally decided to get serious & learn a302svt Member Intro 1 07-19-2007 01:27 PM
Decided to try Debian some guidance required ninadb Debian 2 08-20-2004 12:40 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:36 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration