Search
 
SCRIPT & CODE EXAMPLE
 

C

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
", sum);
//This code can (assuming no arithmetic overflow) be rewritten using a mathematical formula like:
int sum = N * (1 + N) / 2;
printf("sum: %d
", sum);
Comment

PREVIOUS NEXT
Code Example
C :: declaration of arrays 
C :: come fare un programma in c con cui interagire 
C :: ctest run specific test 
C :: increase size of array in c 
C :: transpose of a matrix in c 
C :: split string at space C 
C :: array of pointers to functions 
C :: how to compare string in c 
C :: write to console c 
C :: print name of file argv c 
C :: docker logs follow 
Dart :: python read json from url 
Dart :: flutter text right overflowed 
Dart :: flutter check if string is number dart 
Dart :: how to get whatsapp groups in app flutter programmatically 
Dart :: delete shared preference flutter 
Dart :: dart continue 
Dart :: how to hide notficition bar in flutter 
Dart :: slice string dart 
Dart :: flutter button with icon 
Dart :: flutter snackbar margin 
Dart :: flutter animated container 
Dart :: list of strings in dart 
Dart :: Flutter how to use ListTile Threeline 
Dart :: round off in dart 
Dart :: flutter status bar color 
Dart :: dart loop through list 
Dart :: bottomsheet shape flutter 
Dart :: dart comments 
Dart :: dart convert iterable to list 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =