Skip to content

Update issue1.c#3

Open
compu-TEE wants to merge 9 commits into
MysteriousCoder7:mainfrom
compu-TEE:corrected
Open

Update issue1.c#3
compu-TEE wants to merge 9 commits into
MysteriousCoder7:mainfrom
compu-TEE:corrected

Conversation

@compu-TEE

@compu-TEE compu-TEE commented Mar 1, 2025

Copy link
Copy Markdown

### CHANGES MADE TO EACH FILE

  1. The code copied the exact string, so iterating the for loop backwards gives the reversed string.
  2. The code had a base case of 0 and was using multiplication, which would end up giving us 0 always. Instead, every even number was incremented by 2 starting from 2.
  3. The code had a line where an entire array (array 1) was being stored as an element for the other array (array 2) when it just had to copy. So, the indexing of the array 1 was initialized.
  4. The code was looping with the incorrect limits, corrected them.
  5. In switch-case statements break is necessary as without it every other case after the desired case would be executed. Added break statements after every case.
  6. The desired outputs were reversed in the if-else statement. Just interchanged them.
  7. The code was trying to add an integer to a pointer. De-referenced a pointer so that the addition can take place.
  8. The for loop iterates until the 100th element, but if the index of the null character is less than 100 then we get an undefined behavior. So, the for loop is now iterated until it reaches the null character.
  9. The factorial of 2 was given to be 1 in the code, but it is 2 and the base case has to be either 0 or 1. The base case was changed and the number of 2 was incorporated in the code itself.

changed the limits of iteration
break statement was missing
the desired outputs were reversed in the if-else statement
can't add an integer to a pointer, so had to deference it
after the null character in the string, the output would just lead us to undefined behavior. So the loop is stopped when it reaches the null character
factorial of 2 is 2, not 1 and we can't ignore the cases of 0 and 1
Comment thread issue6.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants