Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <math.h>
- float aryt(int *table, int ile)
- {
- float s1=0;
- s1 = (float)(table[0]+table[ile-1])/2;
- s1 = s1*ile;
- return s1;
- }
- float geom(int *table, int ile)
- {
- int q=0, q2;
- float s2=0;
- q = table[1]/table[0];
- q2 = pow(q, ile);
- if(q==1){
- s2 = table[0] * ile;
- }
- else{
- s2 = table[0]*((1-q2)/(1-q));
- }
- return s2;
- }
- int main()
- {
- int size=0, i;
- printf("Podaj rozmiar tablicy:\n");
- scanf("%d", &size);
- int *table = malloc(size); //dynamiczne rezerwowanie miejsca w pamieci, zwraca wskaznik do nowowo zarezerwowanego miejsca
- srand(time(0)); //losowanie liczb pseudo losowych do tablicy
- for(i=0; i<size; i++){
- table[i] = 1 + rand() % 10;
- printf("%d ", table[i]);
- }
- // free(table); //zwalnanie pamieci
- printf("\n\nSuma ciagu arytmetycznego: %f", aryt(table, size));
- printf("\n\nSuma ciagu geometrycznego: %f", geom(table, size));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement