LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 01-29-2019, 05:29 AM   #181
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513

Quote:
Originally Posted by jsbjsb001 View Post
I appreciate your help jpollard, and I'm sure your right in what you're saying, but it's just getting more and more beyond me at this point. I have no idea why I need to do any of the steps you guys talk about other than it converts it from decimal to hex. I'm not trying to be funny or anything, but it's just beyond me.
It is necessary to understand how to follow an algorithm; this is how a computer steps through a program. EVERY step is important for achieving the goal. Understanding base arithmetic is the first step. The details are important as leaving any step out, or doing them in the wrong order, causes failures.

Will you use this frequently? not often. This specific function is used often enough that it is included as a format specification in printf; as is base 8 notation and base 10 notation. But sometimes doing conversions is necessary. Like if you are trying to print money values... you have special goal - like putting commas every three digits... using scaled values sometimes (which is part of base conversion. Conversion to hex is scaling a value by 16 at every step... But to preserve the information about the scale of the resulting number means you have to do something with the remainders... but the specific thing to do depends on the goal of the scaling).

Numbers inside the processor are always base 2. So any conversion to something else is a base conversion. Using compression is a form of base conversion... So is encryption/decryption (though much more complex than basic number bases).

Everything a computer can do is based on mathematics. It is just the application of math to things not usually considered math that makes it hard to recognize the math. Even doing things like the fonts used for showing things is math - at the simplest, a matrix of dots. But that doesn't look good when scaled... so there are also scalable fonts - which are tables of math parameters to describe combinations of curves and define "inside" and "outside" so that some areas can be filled in, and other areas not filled in. Scaling these to any size (there is a minimum size though) makes the resulting display look good.

Like learning to balance a checkbook, you first have to learn arithmetic. It is just getting used to tracking what is being done, recognizing when side effects can be used (like the remainder is a side effect of division).

One thing that might help with base conversion is writing a program that does the base conversion. Using basic operators of "/" for division and "%" for modulo to get a remainder, is easier than doing long division. But the long division is what the computer uses to get these results of the "/" and "%" operations.

And like many problems, there are special cases that make shortcuts available. Hex and octal conversions produce results that will fit with a specific number of bits (hex, 4 bits, octal 3 bits). So base conversions of these are easy if the original base is 2 (which is what the computer uses). For base 16, every 4 bits of the original value is the desired "remainder". For base 8, every 3 bits. So for these special cases, a different algorithm can be used for the conversion.
Quote:

While it's probably a waste of time asking the following question given the above, I'll ask it anyway;

In the C pdf, it says the following for one of the exercises at the end of the "Program Looping" chapter;
Quote:
2. Write a program to generate and display a table of n and n2, for integer values of n
ranging from 1 to 10. Be certain to print appropriate column headings.
The last part is obvious and was fairly easy, but does the "n2" (with the small "2") mean an "exponent", and therefore n x n ?
That goes to the syntax specification of variable names.
https://en.wikibooks.org/wiki/C_Programming/Variables

A variable name in C is any sequence of characters composed of "a" to "z", "A" to "Z", and the character "_" (which is conventionally used for "special" use as a first character) for the very first character of the variable name.
The rest of the characters for a name can ALSO include the digits "0" through "9".

So n2 is a variable name.

The only other point is that C doesn't include an exponentiation operator. There is a function for that in the math library for real numbers.
Quote:

I've posted my code below, but if the question above does mean "n2" as in an "exponent", then I don't think my code below does that, and I have no idea how to get it to do that. So I'm not even sure what the question is even asking me to do.

Code:
#include <stdio.h>

int main(void)
{

int number, plusnumber = 0;

printf("Table of Triangular Numbers\n");
printf("number    Sum of 2 to number\n");
printf("------    ------------------\n");

for( number = 1; number <= 10; ++number) { 

plusnumber += number; 

printf("%2i       %2i\n", number, plusnumber);
}
return 0;
}
 
2 members found this post helpful.
Old 01-29-2019, 06:52 AM   #182
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Thanks again for your help jpollard. I just don't know what to do. I'm not trying to digress or anything I'm honestly not, and I don't want to waste anyone's time. But I'm clearly no good at maths, I did honestly try, but it's just pissing me off not understanding it. And given what you guys have said about the need to understand it, and I can see why the more I read the C pdf/book, it's starting to look like I just don't have the maths knowledge required for it. And I'm probably gonna be dead by the time I ever can figure it out. So I'm just not sure it's worth trying to continue with it, I do want to learn how to program, but like I said, it's just getting too hard to try and figure the maths out.

I tried to do the following, but it doesn't matter what I try, it just won't work;

Quote:
3. A triangular number can also be generated by the formula
triangularNumber = n (n + 1) / 2
for any integer value of n. For example, the 10th triangular number, 55, can be
generated by substituting 10 as the value for n in the preceding formula.Write a
program that generates a table of triangular numbers using the preceding formula.
Have the program generate every fifth triangular number between 5 and 50 (that
is, 5, 10, 15, ..., 50).
I have no idea how to get it to "generate" every fifth "triangular number between 5 and 50". I put "triangularNumber = n (n + 1) / 2" (I renamed the variables) in my code and it just keeps giving me the following error below, I have no idea what I'm doing wrong, clearly something.

Code:
[james@jamespc devel]$ gcc -Wall -Werror program_looping__exercise3.c -o program_looping__exercise3
program_looping__exercise3.c: In function ‘main’:
program_looping__exercise3.c:14:25: error: called object is not a function or function pointer
 plusnumber = number / 2 (number + 1);
I think I might just use software others have already written. I would mark this thread as SOLVED, but given I haven't really learnt how to write a decent program, let alone C programming, I'm not sure I honestly can if you know what I mean. I just don't see it happening. I would post my code, but I'm probably just wasting my time trying to go any further with this. I'm sorry to have wasted everyone's time.
 
Old 01-29-2019, 04:13 PM   #183
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018
Don't get discouraged, you were actually on the right track.

The exercise states:
Quote:
Write a program to generate and display a table of n and n², for integer values of n ranging from 1 to 10. Be certain to print appropriate column headings.
jpollard misunderstood you -- most likely because the superscript was lost when you cut/pasted it (making it look like a variable named 'n2' when it wasn't). It's just asking you to calculate a table of the squares of n. So yes, as you suspected it's just a matter of doing result = n * n; and outputting it, within a loop.


As for the other formula you were having a problem with, in math they tend to leave out the multiply operators, so when they say something like n(n + 1), that's just a mathematician's way of saying what a programmer would write as n * (n + 1), so whenever you see something like that, you just have to remember to put them back in.

BTW, you may find https://www.mathsisfun.com helpful for filling in some of the gaps in your knowledge, especially the algebra sections.

Last edited by GazL; 01-29-2019 at 04:19 PM.
 
3 members found this post helpful.
Old 01-29-2019, 06:28 PM   #184
Mechanikx
Member
 
Registered: Jul 2018
Distribution: Slackware
Posts: 351

Rep: Reputation: 258Reputation: 258Reputation: 258
jsbjsb001,

I can't really say one way or the other what you should do regarding programming but I will suggest that if you would like to further your studies in math, you should check out this site:

https://www.khanacademy.org/

I studied math for fun for about 4 years before I committed myself to programming. For the last 2 of those 4 years I used this site. Sal has a friendly, informal approach to teaching. It's like having a conversation with a friend. The majority of his lectures are videos (some reading material) where he talks through the concept but he also illustrates with diagrams, examples, etc. He teaches everything from the very basic to the more advanced. There's also a forum where you can ask questions and they'll be answered by other students, math tutors, etc. It's also free, you just have to sign up for a membership.

All the best
 
3 members found this post helpful.
Old 01-30-2019, 07:38 AM   #185
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by jsbjsb001 View Post
Thanks again for your help jpollard. I just don't know what to do. I'm not trying to digress or anything I'm honestly not, and I don't want to waste anyone's time. But I'm clearly no good at maths, I did honestly try, but it's just pissing me off not understanding it. And given what you guys have said about the need to understand it, and I can see why the more I read the C pdf/book, it's starting to look like I just don't have the maths knowledge required for it. And I'm probably gonna be dead by the time I ever can figure it out. So I'm just not sure it's worth trying to continue with it, I do want to learn how to program, but like I said, it's just getting too hard to try and figure the maths out.
I do not believe the term is plural, it would simply be "math", no 's' required.

Regarding the whole topic, all I'm concerned about would be "recognition" that numbers mean certain things, and that you can convert them somehow. The calculator is helpful for that, the part where it converts for you, that is.

What I mean by recognition.

0x30 - what is that? To me, it does mean 48, but it also means "three, sixteens"

Because it is a hex number.

I know that the second digit from the right means "sixteens".

So I know what that number means, by visual inspection.

This is what I mean by recognition.

Go back to base 10. Decimal.

What is the second digit as you move left from the right-most digit?

A: Tens.

If I say, "Show me ninety", you write a nine and then a following zero, because you know that you need nine values of ten.

And you know that this second digit from the right represents tens.

You probably know that intuitively from just "life", however if you think about it, that second digit is "a multiple of ten".

As you head more to the left in digits, you continue to multiply by ten.

Hundreds, thousands, ten thousands, etc. (Show me someone who would not recognize one million. Why? Because that's some expression of money that people would love to see in their pockets.)

So ...

Same thing for another number based system.

Hexadecimal is base 16.

The right most digit is the "ones" digit.

I think you sort of understand that the next digit to the left is the "sixteens" digit.

So as a result if I ask you to represent sixteen in hexadecimal, you end up showing me 0x10. Which is "one value of sixteen".

What's two values of sixteen? 2 x 16 which is 32. How is that in hex? 0x20.

That's really what I wish you to recognize, so that when you are presented with hex numbers, as you very much will be; that you recognize what they mean, and they don't just blow your mind for days on end.

I.e. you can either figure them out, or use your computer calculator to show you the conversion.

That's it. Perhaps get programming, but worry less about the equation of a triangle, or how to calculate the area of a circle. If you're poor at Math, then writing code to compute equations is a bad idea. You can certainly write code to control an I2C device, or GUI code, or database code. No reason to complicate things. And if you understand the math, then writing the code is fine. For instance if you understand how to calculate simple interest, like for a car loan, so you can get the annual interest on some loan, and write a program that calculates your payment for a 5-year car loan, or something like that. If that's too much for you, then it is. Concentrate on some stuff you can do for now.
 
2 members found this post helpful.
Old 01-30-2019, 07:46 AM   #186
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
Don't listen to them. There are people who are programming and those who are teaching programming. So just start to program. Instead of you will be stuck on 'learning programming'. Maybe for months, even year. Just waste of time.
 
1 members found this post helpful.
Old 01-30-2019, 07:50 AM   #187
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by rtmistler View Post
I do not believe the term is plural, it would simply be "math", no 's' required.
maths with an s is a Britishism.
 
3 members found this post helpful.
Old 01-30-2019, 08:52 AM   #188
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018
The first few chapters of the Kochan book are a little over focussed on math(s)¹. The example programs have you calculating triangular numbers, gcd, fibonacci sequence and so on. Non of it is particularly hard, but if you're completely new to the topic I can see how it might be a little daunting having to learn all that while trying to pick up the C language and fundamental programming concepts all at once.


¹ Can confirm. Over here in the UK we keep the 's' from mathematics when we abbreviate.
 
2 members found this post helpful.
Old 01-31-2019, 04:43 AM   #189
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by rtmistler View Post
...
That's it. Perhaps get programming, but worry less about the equation of a triangle, or how to calculate the area of a circle. If you're poor at Math, then writing code to compute equations is a bad idea. You can certainly write code to control an I2C device, or GUI code, or database code. No reason to complicate things. And if you understand the math, then writing the code is fine. For instance if you understand how to calculate simple interest, like for a car loan, so you can get the annual interest on some loan, and write a program that calculates your payment for a 5-year car loan, or something like that. If that's too much for you, then it is. Concentrate on some stuff you can do for now.
The problem is that programming is ALL based on math, and programming is MUCH easier if you are familiar with the basics... which is the arithmetic, and then algebra.

You don't get to control an I2C device or GUI without it.
 
2 members found this post helpful.
Old 01-31-2019, 06:45 AM   #190
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Thanks again guys. I appreciate all of you taking the time to respond, as I know it's not as if anyone has to, so thanks again.

I do take all comments as being helpful, being the reason I've marked them all as helpful, even where some of you differ, I still consider it to be helpful to me. Just don't ask me to explain that statement, because I probably won't be able to give an answer that would make a lot of sense. But never-the-less, and while I'm really still in two minds about continuing with it; I would like to clarify a few things to see if I've understood a few things properly.

Thanks for all the help you have given me jpollard. When you say "arithmetic", do you basically mean the usual stuff being, add, subtract, division, multiply ? And when you say "algebra", you mean basically using letters in place of numbers? (I know there's more to it than that, but without repeating everything I've read on Wikipedia, is that the very basic idea?)

Thanks for your answers and help GazL. I tried what you said, and it worked. But I don't think I got the exercise about getting every 5th number right though.

To be clear: I don't intend on becoming an expert in math, and I don't expect to become one. And given where my maths knowledge is, and while it would be nice, probably not doing any paid programming work either. But thanks Mechanikx for that link, while I will have a look at it, it's probably going to take a lot longer for me to dramatically improve my math knowledge to any great degree than what it took you, so I don't have high hopes about it, but thanks for the link all the same.

Anyhow I've posted what I've done below for you guys to have a look at all the same;

Code:
#include <stdio.h>

int main(void)
{

int number, plusnumber = 0;

printf("\nTable of Triangular Numbers\n");
printf("number    Sum of 2 to number\n");
printf("------    ------------------\n");

for( number = 1; number <= 10; ++number) { 

plusnumber = number * number; 

printf("%2i       %2i\n", number, plusnumber);
}
return 0;
}
(the code above is for exercise 2. The code below is for exercise 3 - which was supposed to get every 5th number which it doesn't from the output I got do)

Code:
#include <stdio.h>

int main(void)
{

int number, plusnumber = 10;

printf("\nTable of Triangular Numbers\n");
printf("number    Sum of 2 to number\n");
printf("------    ------------------\n");

for( number = 0; number <= 10; ++number) {

plusnumber = number * (number + 1) / 2;

printf(" %2i       %2i\n", number, plusnumber);
}
return 0;
}
 
Old 01-31-2019, 07:39 AM   #191
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
It doesn't matter that you initialize plusnumber to 10 versus 0 since you are assigning it a value in the first place.

Whatever you were supposed to do:
Quote:
get every 5th number
Is an unclear statement.

Meanwhile what you are doing with this:
Code:
plusnumber = number * (number + 1) / 2;
Is that you are taking the loop variable, which has values from 0-10.
Multiplying each iteration of the loop variable times the loop variable plus one, then divided by two:
Code:
0: 0 + (0 + 1)/2 = 0
1 * (1 + 1)/2 = 1
2 * (2 + 1)/2 = 3
3 * (3 + 1)/2 = 6
4 * (4 + 1)/2 = 10
5 * (5 + 1)/2 = 15
6 * (6 + 1)/2 = 21
7 * (7 + 1)/2 = 28
8 * (8 + 1)/2 = 36
9 * (9 + 1)/2 = 45
10 * (10 + 1)/2 = 55
My guess is that you are trying to make the computation result increase by five each time.

A set of terms to remember:
Please My Dear Aunt Sue
Parenthesis
Multiplication
Division
Addition
Subtraction

This is called PRECEDENCE and it governs the order of operations.

Parenthesis wins over all
Multiplication is above Division
And so forth.

This also goes Left to Right. Thus if you have several of the same operation, (a * b * c * d), then you do them left to right.

I mean, I agree that you need to know Math to program effectively, however you are trying code a numeric algorithm. Bad idea in my humble opinion, you don't seem to grasp numeric algorithms well at all.

Be that it may, what I would recommend would be the following:
  1. Learn how to use GDB and use GDB on all your source files.
  2. I prefer to use GDB through emacs, it provides a great starter interface to give you visual and symbolic debugging. You actually can compile from emacs as well.
  3. Set breakpoints, inspect variables, and single step through your code so that you learn about what it is doing.
  4. A great alternate would be to add a great deal of printf() statements about everything, or including far more details that you have.
Code:
int interim_1, interim_2;

    for( number = 0; number <= 10; ++number) {

        plusnumber = number * (number + 1) / 2;

        interim_1 = number + 1;
        interim_2 = interim_1 * number;

        printf("Loop variable value: %d\tResultant calculation: %d\nInterim_1: %d\tInterim_2: %d\n", number, plusnumber, interim_1, interim_2);
    }

Last edited by rtmistler; 01-31-2019 at 07:40 AM.
 
2 members found this post helpful.
Old 01-31-2019, 08:18 AM   #192
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018
The every fifth number thing is very simple.

Take the for loop

for ( n = 0 ; n <= 50 ; ++n ) {
...
}

++n is a fancy way of doing n += 1, which is a shorthand way of saying n = n + 1


If you want to go by every 5, just add 5 instead of 1, so instead of ++n use n = n + 5


I think people are over-egging the need for math here. You'll need to understand basic algebra (using letters in place of numbers: because that is essentially what variable expressions are). For C you'll need to understand Binary representation, and Hexadecimal, but the book covers that. C starts getting confusing when you get into pointers and pointer arithmetic and stuff like that (not helped by the fact that the language itself is a little inconsistent) but these are topics for later.

Anyway, rather than give up on programming completely, which would be a shame as it's both a wonderful skill to have and a lot of fun, may I suggest that if you're struggling with C then start with something like python.

When I first started I learnt with BASIC which is a much easier language than C is. I also used to love Turbo Pascal back in those days, but both of those are seldom heard of these days. You can always come back to C in the future as your second language.

Last edited by GazL; 01-31-2019 at 08:21 AM.
 
1 members found this post helpful.
Old 01-31-2019, 09:03 AM   #193
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Thanks Guys.

Thanks for answering that for me GazL. It's not really the C that's hard, yes there are a lot of concepts to cover, but it's the math that's killing me. Even if I learnt Python (not going to rule it out for later on), it would not solve my math (or lack of skills) problems, and I would like to learn C because if I can do that; I'd think learning any other programming language should be a lot easier.

It's all honesty been fairly simple learning C itself, as I did read in that C book about how "++n" is (as you said), the shorthand way of writing "n = n + 1", it just seemed like a good idea to shorten it to me, which was why I used it. It's just the math side of things once again that I'm not really getting.

(and thanks RT for explaining what you did about how the loop works)
 
Old 01-31-2019, 09:38 AM   #194
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I recommend starting a new thread in General where you explain that you're trying to learn Mathematics for programming and describe the problems which you are having.

Until you can intuitively grasp some of the Math concepts, I fear you'll still end up blocked with the exercises you persist with trying in the C course you are following.
 
Old 01-31-2019, 10:17 AM   #195
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018
Quote:
Originally Posted by rtmistler View Post
A set of terms to remember:
Please My Dear Aunt Sue
Parenthesis
Multiplication
Division
Addition
Subtraction

This is called PRECEDENCE and it governs the order of operations.

Parenthesis wins over all
Multiplication is above Division
And so forth.

Forgive me for interjecting, but this is not true. Multiplication is equal precedence to both division and modulo: all of which are processed left to right.
e.g.
Code:
#include <stdio.h>

int main ()
{
    printf("%d\n", 30 / 3 * 5) ;
    printf("%d\n", 30 / 5 * 3) ;
    printf("%d\n", 30 / (5 * 3)) ;
    return 0;
}
if multiplication did have precedence over division as you state then these would all show the same result of 2, instead of 50, 18 and 2.

ref:
https://en.cppreference.com/w/c/lang...tor_precedence

Last edited by GazL; 01-31-2019 at 10:35 AM.
 
1 members found this post helpful.
  


Reply

Tags
c programming, learning c



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 08:04 PM
Decided to try Lubuntu 14.04 on my netbook... pcninja Ubuntu 4 04-20-2014 08:18 PM
Finally decided to get serious & learn a302svt LinuxQuestions.org Member Intro 1 07-19-2007 12:27 PM
Decided to try Debian some guidance required ninadb Debian 2 08-20-2004 11:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:19 PM.

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