首页 > 代码库 > Wikioi 1202

Wikioi 1202

1201 最小数和最大数 

题目描述 Description

求n个数的和

输入描述 Input Description

第一行一个整数n

接下来一行n个整数

输出描述 Output Description

所有数的和

样例输入 Sample Input

4

1 2 3 4

样例输出 Sample Output

10

数据范围及提示 Data Size & Hint

n<=100

所有数的和<=231-1

 

 

pass code:

 算法思想:冒泡排序

#include <stdio.h>int main(){	int n = 0, a[100] = { 0 }, i = 0, j = 0, t = 0;	int max = 0, min = 0;	scanf_s("%d", &n);	while (i < n)	{		scanf_s("%d", &a[i]);		i++;	}	for (i = 1; i <= n; i++)	{		for (j = 0; j <= n -1-i; j++)		{			if (a[j] > a[j + 1])			{				t = a[j];				a[j] = a[j + 1];				a[j + 1] = t;			}		}	}	max = a[i-2];	min = a[0];	printf("%d %d", min, max);	getchar();	getchar();}

 

 

---------------------------------------------------------------------------------------------------------------------------

个人平时学习总结 ^_^

---------------------------------------------------------------------------------------------------------------------------