-
Notifications
You must be signed in to change notification settings - Fork 0
new code #133
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
base: master
Are you sure you want to change the base?
new code #133
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -148,6 +148,31 @@ int main(int argc, const char* argv[]) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unsigned *myvariablename = new unsigned; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *myvariablename = 10000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| printf("%d\n", *myvariablename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unsigned __int64 sum = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // sum up all the numbers from 0 to 9999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (unsigned x=0; x<*myvariablename; x++) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sum += x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| printf("%llu\n", sum); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sum = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // sum up all the numbers from 0 to 9999 N times | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (unsigned x=0; x<*myvariablename; x++) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (unsigned y=0; y<*myvariablename; y++) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+151
to
+166
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unsigned *myvariablename = new unsigned; | |
| *myvariablename = 10000; | |
| printf("%d\n", *myvariablename); | |
| unsigned __int64 sum = 0; | |
| // sum up all the numbers from 0 to 9999 | |
| for (unsigned x=0; x<*myvariablename; x++) | |
| { | |
| sum += x; | |
| } | |
| printf("%llu\n", sum); | |
| sum = 0; | |
| // sum up all the numbers from 0 to 9999 N times | |
| for (unsigned x=0; x<*myvariablename; x++) | |
| { | |
| for (unsigned y=0; y<*myvariablename; y++) | |
| unsigned myvariablename; | |
| myvariablename = 10000; | |
| printf("%d\n", myvariablename); | |
| unsigned __int64 sum = 0; | |
| // sum up all the numbers from 0 to 9999 | |
| for (unsigned x=0; x<myvariablename; x++) | |
| { | |
| sum += x; | |
| } | |
| printf("%llu\n", sum); | |
| sum = 0; | |
| // sum up all the numbers from 0 to 9999 N times | |
| for (unsigned x=0; x<myvariablename; x++) | |
| { | |
| for (unsigned y=0; y<myvariablename; y++) |
Copilot
AI
Jul 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Instead of dynamically allocating a single unsigned, declare it as a local variable (e.g., unsigned myVariableName = 10000;).
| unsigned *myvariablename = new unsigned; | |
| *myvariablename = 10000; | |
| printf("%d\n", *myvariablename); | |
| unsigned __int64 sum = 0; | |
| // sum up all the numbers from 0 to 9999 | |
| for (unsigned x=0; x<*myvariablename; x++) | |
| { | |
| sum += x; | |
| } | |
| printf("%llu\n", sum); | |
| sum = 0; | |
| // sum up all the numbers from 0 to 9999 N times | |
| for (unsigned x=0; x<*myvariablename; x++) | |
| { | |
| for (unsigned y=0; y<*myvariablename; y++) | |
| unsigned myvariablename = 10000; | |
| printf("%d\n", myvariablename); | |
| unsigned __int64 sum = 0; | |
| // sum up all the numbers from 0 to 9999 | |
| for (unsigned x=0; x<myvariablename; x++) | |
| { | |
| sum += x; | |
| } | |
| printf("%llu\n", sum); | |
| sum = 0; | |
| // sum up all the numbers from 0 to 9999 N times | |
| for (unsigned x=0; x<myvariablename; x++) | |
| { | |
| for (unsigned y=0; y<myvariablename; y++) |
Copilot
AI
Jul 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This nested loop results in O(n²) complexity and may impact performance for large values. Consider whether the double summation is necessary or can be optimized.
| for (unsigned x=0; x<*myvariablename; x++) | |
| { | |
| for (unsigned y=0; y<*myvariablename; y++) | |
| { | |
| // nested loop | |
| sum += x; | |
| } | |
| } | |
| printf("%llu\n", sum); | |
| // Calculate the sum directly using a mathematical formula | |
| sum = *myvariablename * ((*myvariablename - 1) * *myvariablename / 2); | |
| // The formula computes the sum of x repeated *myvariablename times for all x from 0 to *myvariablename - 1 | |
| printf("%llu\n", sum); | |
| printf("%llu\n", sum); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format specifier
%dis for signed integers; for an unsigned value use%uto ensure correct output and defined behavior.