Friday, November 2, 2012

Tugas V-1

Name: Chea Lida
Major:TMD

1. Create the program to insert n integer value in the array and then to returned data array, the total number and average them!


#include <stdlib.h>//Accessing library stdio.h's file parse it exists printf's function()
#include <stdio.h>//Accessing library stdlib.h's file parse it exists system's function( "pause")

int main()//main's function that shall there
{
       int num[10];//declare array num that content 10 character
       int count = 0, k;
       float total = 0;
       printf("Enter the amount of data you want: (1 - 10)\n");//display text Enter the amount of data you want
      
       while(count <= 0 || count > 10){//looping start if count<=0 or count >10
              scanf("%d", &count);// accepting input from user keep it in variable count
       }
      
       for(k = 0; k < count; k++){// looping start k=0 end k < count and step k++
              printf("\nEnter %d amount : ", k+1); //display k+1
              scanf("%d", &num[k]); // accepting input from user keep it in variable num
       }

       for(k = 0; k < count; k++){// looping start k=0 end k < count and step k++
              printf("\nData %d that u have been insert : %d", k+1, num[k]); //display k+1 and num[k]
              total = total + num[k]; //calculate total
       }

       printf("\n\nTotal amount that have insert : %.0f\n", total);//display total
       printf("Average amount all the data you insert: %.3f\n", total/count); // display total/count

       system("pause");
}




No comments:

Post a Comment