Horje
Program optimization Code Example
Program optimization
//Computational tasks can be performed in several different ways with 
//varying efficiency. 
//A more efficient version with equivalent functionality is known as a strength reduction. 
//For example, consider the following C code snippet whose intention is to 
//obtain the sum of all integers from 1 to N:
int i, sum = 0;
for (i = 1; i <= N; ++i) {
  sum += i;
}
printf("sum: %d\n", sum);
//This code can (assuming no arithmetic overflow) be rewritten using a mathematical formula like:
int sum = N * (1 + N) / 2;
printf("sum: %d\n", sum);




C

Related
getopt optstr Code Example getopt optstr Code Example
manasa loves maths solution IN C Code Example manasa loves maths solution IN C Code Example
parcel-bundler include image files Code Example parcel-bundler include image files Code Example
Writing tests for API requests Code Example Writing tests for API requests Code Example
4 byte alignment c code Code Example 4 byte alignment c code Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10