等比数列实现

This commit is contained in:
LingZhaoHui 2022-12-06 22:40:50 +08:00
parent d37a9e5429
commit 5b01488ce7
1 changed files with 25 additions and 0 deletions

25
base/dengbishulie.c Normal file
View File

@ -0,0 +1,25 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
if(argc != 4) {
return -1;
}
int a1 = atoi(argv[1]);
int q = atoi(argv[2]);
int n = atoi(argv[3]);
printf("a1=%d, n=%d,q=%d\n", a1, n, q);
int i=0;
int sum = 0;
int a = a1;
while (i < n) {
sum += a;
a *= q;
i++;
}
printf("sum=%d\n", sum);
return 0;
}