fordea / c-programming-a-modern-approach Goto Github PK
View Code? Open in Web Editor NEWSolutions to exercises and projects in the textbook C Programming: A Modern Approach, 2nd Edition.
Solutions to exercises and projects in the textbook C Programming: A Modern Approach, 2nd Edition.
This code has multiple issues:
`#include <stdio.h>
int main(void)
{
int hour, minute;
printf("Enter a 24-hour time: ");
scanf("%d :%d", &hour, &minute);
int ampm_hour = hour >= 12 ? hour % 12 : hour;
printf("Equivalent 12 hour time: %d:%d %s", ampm_hour, minute, ampm_hour <= 12 ? "AM" : "PM");
return 0;
}`
They include:
Your code is
printf("%d\n", i >= 0 ? 1 : -1);
Actually the code on the book is
printf("%d\n", i >= 0 ? i : -i);
hence I believe the answer is always 17 both when i
is 17 and when i
is -17
In ex5, the explanation of the answer has some error.
When the format string "%f%d%f" in scanf processes the input "12.3 45.6 789",
the order is that:
first- for %f (x) read '1', '2', '.', '3', ' '
Since ' ' can't be the part of the item that corresponds to %f (x),
' ' is put back to the buffer and 12.3 is assigned to x;
second- for %d (i) read ' ', '4', '5', '.'
The first W.S(white space) is discarded.
Since '.' can't be the part of the item that corresponds to %d (i),
'.' is put back to the buffer and 45 is assigned to i;
third- for %f (y) read '.', '6', ' '
Since ' ' can't be the part of the item that corresponds to %f (y),
' ' is put back to the buffer and 0.6 is assigned to y;
since loop does not increment, this will return 0 for any two strings with the same first character.
I suggest replacing
while (s == t)
with
while (s++ == t++)
It always prints 0 when compiled with GCC
Should be printf("Factorial of %d: %.0Lf", n, factorial);
(upper case L)
Before incrementing idx_first_item
:
QUEUE_MAX
, just like in queue()
:The two format strings in exercise (b) are not equivalent.
main.c.txt
3.25 must be 3.75
This is the data offered by the author.
The printout of the data in the book is "Pair", but your codes tests resulting "High card".
Considering the repo's last update is a few years ago, hope other friend can provide a better code.
Wrong value in d) 7.5 / 2 should be 3.75
Hi, I think I found an error in one of your files. In Chapter 7, Exercise 3, you list 4 data types and ask which ones aren't legal. Then you say:
The identifier in (c) 'short float' is not legal.
I believe the (c) should actually be (b). (b) is the 'short float'. (c) is listed as 'long double'
In the answer to (b) it says: "The g function: a (g parameter), b and c external variables."
But there is a local c variable declared inside the function.
hi! I think I catch some error in ex2(b).
In 03.txt, you wrote that "%d-%d-%d", "%d -%d -%d" are equivalent.
But there is a problem.
Second string can process the input, "1 -1 -1" and first string can not.
Because when scanf process the character '-', it corresponds to character ' '.
So it stops.
Sorry for my english skill TT
have a nice day!
Project 07.c of cj13 has wrong output because it is missing addition condition. As we enter 20 of yields wrong output that can be fixed with adding else if(ones !=0)
Line 51: found = false should be found = true.
Thank you very much for putting your solution out there!
At the above line, you're allocating sizeof(char*)
bytes more than needed.
Hey, I hope not to be too nitpicky, but I have found a typo in this file. There is a trailing colon which should, of course, not be there
I hope not to disturb you
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.