Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************/
- /** 20150326 Exam 04 **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2015/03/03 pm.12:00 **/
- /***************************************/
- #include <stdio.h>
- #include <stdlib.h>
- template <typename T> T GetSquareAverage(T array[], int count){
- T sum = 0;
- for (int i = 0; i < count; i++){
- sum += array[i] * array[i];
- }
- return sum / count;
- }
- int main(){
- for (int i = 0; ; i++){
- int count = 0;
- scanf("%d", &count);
- if (count == 0){
- break;
- }
- else{
- //First time use Integer Type
- if (i == 0){
- int *inArray = (int *)malloc(count * sizeof(int *));
- for (int j = 0; j < count; j++)
- scanf("%d", &inArray[j]);
- printf("Answer: %d\n", GetSquareAverage(inArray, count));
- delete [] inArray;
- }
- //After first time, all is Float Type
- else if(i == 1){
- float *inArray = (float *)malloc(count * sizeof(float *));
- for (int j = 0; j < count; j++)
- scanf("%f", &inArray[j]);
- printf("Answer: %f\n", GetSquareAverage(inArray, count));
- delete [] inArray;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment