Skip to content

Update add_2_integers.c #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions 00_operators/add_2_integers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
#include <stdio.h>

// start of the main function
int main(void)
{
printf("Starting the program here: \n");

int integer1, integer2; // first and second number to be entered by the user
// int integer2; // second number to be entered by the user

printf("Enter the first Integer:\n"); //prompt
scanf("%d", &integer1); // read the integer

printf("Enter the second Integer:\n"); //prompt
scanf("%d", &integer2); // read the second integer

int sum = integer1 + integer2; // assign the value of the total expression to sum
printf("Sum is %d\n", sum);

}// end of the main function
int main() {
int a, b, sum;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind, that this codebase is intended for readers looking to learn C, so some obvious redundant efforts are actually intentionally, this include the print line here to let the user observe the start of the program execution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay purely understand that, many people have problems on many things. Thank you for your feedback, I appreciate that 🙏

// Get the first integer from the user
printf("Enter the first integer: ");
scanf("%d", &a);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, i would argue that beginners be introduce to naming variables as meaningful constructs, since this doesn't offer any technical improvement over the previous structure, it is not an update , so we can stick with the longer variable names, nice work though 👌

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I understand that and thank you for your feedback.


// Get the second integer from the user
printf("Enter the second integer: ");
scanf("%d", &b);

// Add the two numbers
sum = a + b;

// Display the result
printf("The sum of %d and %d is %d\n", a,b, sum);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥🔥🔥🔥


return 0;
}// end of the main function
16 changes: 11 additions & 5 deletions 00_operators/comma_operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
#include <stdio.h>

/* function main starts program execution */
int main(void)
int main()
{
int a;
a = 89, 1336;
printf("%d\n", a);
}
int a, b, c;

a = (b = 5, c = 10);

printf("a = %d\n", a);
printf("b = %d\n", b);
printf("c = %d\n", c);

return 0;
}