//
// main.c
// 53 - 数列求和 - 李洪强
//
// Created by vic fan on 16/10/15.
// Copyright ? 2016年 李洪强. All rights reserved.
//
#include <stdio.h>
int main(int argc, const char * argv[]) {
//1 ,3,5,7...
//中间有多少项相加
//sum = 0 + 1;
//sum = 1 + 3;
//sum = 4 + 5;
//sum += 2 *i + 1;
int i = 0;
int sum = 0;
while (i < 49) {
sum += 2 *i + 1;
i++;
}
printf("%d\n",sum);
//*******************
//和
int sum = 0;
//公差
int gongCha = 1;
//首项
int shouXiang = 1;
int i = 0;
while (i < 100) {
sum += gongCha *i +shouXiang;
i++;
}
printf("%d\n",sum);
return 0;
}
时间: 2024-10-03 06:03:41