编写一个程序,把一个数组中的负数打印出来,并输出这些负数的和。数组为:-5,65,-32,98,-54,0,-307

日期:2011-03-23 02:51:32 人气:1

编写一个程序,把一个数组中的负数打印出来,并输出这些负数的和。数组为:-5,65,-32,98,-54,0,-307

int main(int argc, char* argv[]) { int s[] = {5, 65, -32, 98, -54, 0, -307}; int t, sum = 0, i; for (i = 0; i < 7; i++) { t = (s[i] < 0); switch (t) { case 1: sum += s[i]; printf("%i\n", s[i]); break;
    A+
热门评论