Search
 
SCRIPT & CODE EXAMPLE
 

C

take array as input in c

int size=5;
int array[size]; // array of size=5;

for(i=0;i<size;i++){
   scanf("%d",&array[i]);
                }
Comment

Array Input/Output in C

// Program to take 5 values from the user and store them in an array
// Print the elements stored in the array
#include <stdio.h>

int main() {
  int values[5];

  printf("Enter 5 integers: ");

  // taking input and storing it in an array
  for(int i = 0; i < 5; ++i) {
     scanf("%d", &values[i]);
  }

  printf("Displaying integers: ");

  // printing elements of an array
  for(int i = 0; i < 5; ++i) {
     printf("%d
", values[i]);
  }
  return 0;
}
Comment

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("
Elements in array are: ");
    for(i=0; i<N; i++)
    {
        printf("%d, ", arr[i]);
    }

    return 0;
}
Comment

printing out an array in c from user input

#include <stdio.h>
 
int main()
{
    int a[1000],i,n;  
 
     printf("Enter size of array: ");
    scanf("%d",&n);
 
     printf("Enter %d elements in the array : ", n);
    for(i=0;i<n;i++)
    {
        scanf("%d", &a[i]);
    }
 
    printf("
Elements in array are: ");
    for(i=0;i<n;i++)
 
    {
        printf("%d  ", a[i]);
    }
 
    return 0;
}
Comment

C Input and Output Array Elements

// take input and store it in the 3rd element
​scanf("%d", &mark[2]);

// take input and store it in the ith element
scanf("%d", &mark[i-1]);
Comment

PREVIOUS NEXT
Code Example
C :: solana-test-validator log 
C :: c check if character is a space 
C :: windows forms picturebox change image 
C :: sort names in array in c 
C :: link list c 
C :: selection sort c 
C :: convert string to int c 
C :: continue statement in c 
C :: C program for float division of numbers 
C :: recursive in c 
C :: Complete the function in the editor. It has one parameter: an array, . It must iterate through the array performing one of the following actions on each element: 
C :: Initialization of a 3d array in c 
C :: declaration in c 
C :: c assignment operators 
C :: c programming exercises 
C :: threads in c 
C :: What should main() return in C? 
C :: check command line input is a number in c 
C :: c functions 
C :: deleting a word with copy fuction c code 
C :: Number 10 
C :: what happens if i acess a freed variable in c 
C :: c program for fibonacci series 
C :: scranton inhabitants 
C :: windows block application au demarrage regegit 
C :: reading arrays from stdin c 
C :: Entering raw mode 
C :: c type conversion 
C :: command line coursera 
C :: os.listdir to array 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =