Answers for "c program to input an array and output the different element"

C
0

input array elements in c

#include <stdio.h>

int main(){
    int i,sum,max,min,avg,size;
   
    printf("ENter array length : \n");
    scanf("%d",&size);
    
    int ara[size];
    
     printf("Enter array elements:\n");
     for(i = 0; i < size;  i++){
        scanf("%d", &ara[i]);
     }
     
   
    
    sum=0;
    max=ara[0];
    min=ara[0];
    for(i = 0; i < size; i++){
        printf("Your array elements are %d\n",ara[i]);
        sum+=ara[i];
        if(ara[i] > max){
            max = ara[i];
        }
        if(ara[i] < min){
            min = ara[i];
        }
    }
    avg=sum/size;
    
    printf("Sum is %d\n",sum);
    printf("Average is %d\n",avg);
    printf("Max number is %d\n",max);
    printf("Min number is %d\n",min);
    
    
    return 0;
}
Posted by: Guest on July-13-2021
0

Program to input and print array elements in c

/**
 * C program to read and print elements in an array
 */

#include <stdio.h>
#define MAX_SIZE 1000 // Maximum array size

int main()
{
    int arr[MAX_SIZE]; // Declare an array of MAX_SIZE
    int i, N;

    /* Input array size */
    printf("Enter size of array: ");
    scanf("%d", &N);

    /* Input elements in array */
    printf("Enter %d elements in the array : ", N);
    for(i=0; i<N; i++)
    {
        scanf("%d", &arr[i]);
    }


    /*
     * Print all elements of array
     */
    printf("\nElements in array are: ");
    for(i=0; i<N; i++)
    {
        printf("%d, ", arr[i]);
    }

    return 0;
}
Posted by: Guest on March-24-2022

Code answers related to "c program to input an array and output the different element"

Code answers related to "C"

Browse Popular Code Answers by Language