C/Zaawansowane operacje matematyczne: Różnice pomiędzy wersjami

Usunięta treść Dodana treść
m →‎sumowanie: program
Linia 120:
* <math>n</math> to '''górna granica sumowania'''.
Wyrażenie „i = m” pod symbolem sumowania oznacza, że indeks <math>i</math> rozpoczyna się od wartości <math>m.</math> Następnie dla każdego kolejnego wyrazu indeks <math>i</math> jest zwiększany o 1, aż <math>i</math> osiągnie wartość <math>n</math> (tj. <math>i = n</math>), który jest ostatnim wyrazem sumowania.
 
 
<syntaxhighlight lang="c">
#include <stdio.h>
 
int summation(const int m, const int n )
{
int s = 0;
for(int i=m; i<=n; i++)
{
s += i;
}
return s;
}
 
 
 
int main()
{
int sum;
int m = 1; // lower index
int n = 100; // upper index
sum = summation(m,n);
printf("sum of integer numbers from %d to %d is %d\n", m, n, sum);
</syntaxhighlight>
 
<syntaxhighlight lang="bash">
gcc s.c -Wall -Wextra
./a.out
sum of integer numbers from 1 to 100 is 5050
</syntaxhighlight>
 
===produkt ( iloczyn) ===