Use scanf to read data into array : Array scanf « Array « C Tutorial

Home
C Tutorial
1.Language
2.Data Type
3.String
4.printf scanf
5.Operator
6.Statement
7.Array
8.Function
9.Structure
10.Pointer
11.Memory
12.Preprocessor
13.File
14.Data Structure
15.Search Sort
16.Wide Character String
17.assert.h
18.ctype.h
19.math.h
20.setjmp.h
21.signal.h
22.stdio.h
23.stdlib.h
24.string.h
25.time.h
26.wctype.h
C / ANSI-C
C++
C++ Tutorial
Visual C++ .NET
C Tutorial » Array » Array scanf 
7.3.1.Use scanf to read data into array
#include <stdio.h>

int main(void)
{
  int numbers[10];
  int count = 10;
  long sum = 0L;
  float average = 0.0f;

  printf("\nEnter the 10 numbers:\n");
  int i;

  for(i = 0; i < count; i ++)
  {
    printf("%2d> ",i+1);
    scanf("%d", &numbers[i]);
    sum += numbers[i];
  }

  average = (float)sum/count;

  printf("\nAverage of the ten numbers entered is: %f\n", average);
  return 0;
}
Enter the 10 numbers:
      1> 2
      2> 3
      3> 1
      4> 2
      5> 1
      6> 1
      7> 1
      8> 2
      9> 1
     10> 1
     
     Average of the ten numbers entered is: 1.500000
7.3.Array scanf
7.3.1.Use scanf to read data into array
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.