배열의 합
using System.Collections;
public class ExTriangle : MonoBehaviour {
// Use this for initialization
void Start () {
float[] a = new float[]{1.0f, 2.0f, 3.0f, 4.0f, 5.0f} ;
float[] b = new float[]{10.0f, 20.0f, 30.0f, 40.0f, 50.0f} ;
float s = GetSum (a[0], a[1], a[2], a[3]);
print (s);
//float s1;
//s1 = GetSum1(a);
//print (s1);
float s2;
s2 = GetSum1 (a, b);
print (s2);
float sum3 = 0;
for(int i = 0; i < a.GetLength(0); i++){
sum3 = a[i] + b[i];
print (a[i] +" + " + b[i] + " = " + sum3);
}
}
/*
string GetDay(int day){
if(day == 1)
return "Hello";
else
return "world";
}
*/
float GetSum(float a, float b, float c, float d){
float sum = a + b + c + d;
return sum;
}
float GetSum1(float[] a, float[] b){
float sum1 = 0;
for(int i = 0; i < a.Length; i++){
sum1 = a[i] + b[i];
print (a[i] + " + " + b[i] + "=" + sum1);
}
return sum1;
}
// Update is called once per frame
void Update () {
}
}