1. 程式人生 > >求10個整數中的最大值

求10個整數中的最大值

求10個整數中的最大值
#include <stdio.h>
#include <windows.h>
int main()
{
int a[] = { 12, 15, 45, 78, 21, 36, 42, 69, 96, 86 }; //定義一個數組a
int size = sizeof(a) / sizeof(a[10]); //獲取陣列中元素的個數
int max = a[0]; //陣列中元素從0開始
int i = 1;
for (i; i < size;i+=1) //如果i小於size,i加1
if (max < a[i]) //如果這個值小於陣列i,則這個數就是最大值
{
max = a[i];
}
printf("%d\n", max); //列印這個最大值
system(“pause”);
return 0;
}