• Breaking News

    Funny Coder

    Funny coder is an open source web for interested programmer. It is a programming environment.It's a way where you can code with fun.

    Monday, April 11, 2016

    C Code of initializing an one dimensional Array

    A Simple Program Using One - dimensional Array

     A one dimensional array is used when it is necessary to keep a large number of items in memory and reference all the items in a uniform manner.

    Write a program to find average marks obtained by a class of 30 students in a test:



    #include<stdio.h>
    void main( )
    {
        int avg, sum = 0 ;
        int i ; int marks[30] ; /* array declaration */
        for ( i = 0 ; i <= 29 ; i++ )
        {
             printf ( “\nEnter marks “ ) ;
             scanf ( “%d”, &marks[i] ) ; /* store data in array */
        }
        for ( i = 0 ; i <= 29 ; i++ )
           sum = sum + marks[i] ; /* read data from an array*/
           avg = sum / 30 ;
    printf ( “\nAverage marks = %d”, avg ) ;
    }





    No comments:

    Post a Comment

    Fashion

    Beauty

    Travel