//
// main.c
// 练习2
//
// Created by 李言 on 15/6/18.
// Copyright (c) 2015年 ly. All rights reserved.
//
#include <stdio.h>
// 题目:提示用户输入一个正整数n,利用while循环计算并输出:1-2+3-4+5-6+7…+n的和
int main(){
int num, sum = 0;
printf("请输入一个整数\n");
scanf("%d", &num);
if(0 == num%2){
sum = -(num/2);
}else sum = -(num-1)/2+num;
printf("%d\n", sum);
return 0;
} |
|