arry in c program

C Programming Arrays



An array is a collection of a fixed number of values of a single type. For example: if you want to store 100 integers in sequence, you can create an array for it.
int data[100];
The size and type of arrays cannot be changed after its declaration.
Arrays are of two types:
  1. One-dimensional arrays
  2. Multidimensional arrays (will be discussed in next chapter)



How to declare arrays : 

data_type array_name[array_size];


program code : 


#include<stdio.h>
int main()
{
    int n,i;
    int num[100];
    printf(" declared array of elements size : ");
    scanf("%d",&n);
    printf("Ente the arry  elements number : ");
    for(i=0; i<n; i++)
    {
        scanf("%d",&num[i]);
        printf("%d ",num[i]);
    }
    return 0;
}



output : 






program code: 



#include<stdio.h>
int main()
{
    int nu[6];
    int i,j;
     printf("Ente the arry  elements number : ");
    for(i=0;i<6;i++){
        scanf("%d",&nu[i]);
    }
    for(j=0;j<6;j++){
        printf("%d ",nu[j]);
    }
    return 0;
}


output :






program code : 

#include<stdio.h>
int main()
{
    int i;
    int ava,sum=0;
    int b[5];
    printf("Enter the 1d dimensional arry :");
    for(i=0; i<5; i++)
    {
        scanf("%d",&b[i]);
        sum=sum+b[i];
      
    }
    ava=sum/5;
    printf("\n sum of arry : %d\n",sum);
    printf(" Avareg %d",ava);


    return 0;
}


output :







No comments

Powered by Blogger.