可变参数求和

来源:互联网 发布:unity3d 点击物体 编辑:程序博客网 时间:2024/06/09 17:47




#include <stdio.h>#include <stdlib.h>//可变参数求和 /* run this program using the console pauser or add your own getch, system("pause") or input loop */int sum(int count,...){int* pt = &count +1;int i = 0;int ret = 0;for(i=0;i<count;i++){ret += *pt++;}return ret;}int main(int argc, char *argv[]) {printf("Sum = %d\n",sum(10,1,2,3,4,5,6,7,8,9,10));return 0;}


0 0
原创粉丝点击