C program to input an array from a sequence of space-separated integers Last Updated : 15 Jul, 2021 Comments Improve Suggest changes Like Article Like Report Given a string S consisting of space-separated integers, the task is to write a C program to take the integers as input from the string S and store them in an array arr[]. Examples: Input: S = "1 2 3 4"Output: {1, 2, 3, 4} Input: S = "32 12"Output: {32, 12} Approach: The idea is to solve the given problem is to use getchar() function to check if a '\n' (newline) occurs is found while taking input and then stop the input. Follow the step below to solve the given problem: Initialize a variable, say count, which is used to store the index of the array element.Initialize an array arr[] of size 106 to store the elements into the array.Iterate using a do-while loop until newLine occurs and perform the following steps:Store the current value at index count as scanf("%d ", &arr[count]); and increment the value of count.If the next character is not endline, then continue. Otherwise, break out of the loop.After completing the above steps, print the elements stored in the array. Below is the implementation of the above approach: C // C program for the above approach #include <stdio.h> // Driver Code int main() { // Stores the index where the // element is to be inserted int count = 0; // Initialize an array int a[1000000]; // Perform a do-while loop do { // Take input at position count // and increment count scanf("%d", &a[count++]); // If '\n' (newline) has occurred // or the whole array is filled, // then exit the loop // Otherwise, continue } while (getchar() != '\n' && count < 100); // Resize the array size to count a[count]; // Print the array elements for (int i = 0; i < count; i++) { printf("%d, ", a[i]); } return 0; } Output: Comment More infoAdvertise with us Next Article C program to input an array from a sequence of space-separated integers A ashokmahendrakar Follow Improve Article Tags : Strings Technical Scripter C Programs DSA Arrays c-input-output +2 More Practice Tags : ArraysStrings Similar Reads C program to sort an array using pointers Given an array of size n, the task is to sort this array using pointers in C. Examples: Input: n = 5, arr[] = {0, 23, 14, 12, 9} Output: {0, 9, 12, 14, 23} Input: n = 3, arr[] = {7, 0, 2} Output: {0, 2, 7} Approach: The array can be fetched with the help of pointers with the pointer variable pointin 2 min read How to Find the Range of Numbers in an Array in C? The range of numbers within an array is defined as the difference between the maximum and the minimum element present in the array. In this article, we will learn how we can find the range of numbers in an array in C. Example Input:int arr[] = { 23, 12, 45, 20, 90, 89, 95, 32, 65, 19 }Output: The ra 2 min read How to Find the Mode of Numbers in a Sorted Array in C? The mode of the given numbers can be defined as the value that occurs the most in the given dataset or the value with the highest frequency. In this article, we will learn how to find the mode of all elements in a sorted array of integers in C. Example: Input:myArray = {1, 2, 3, 3, 5, 5, 5, 5, 6, 7} 2 min read C Program to Split a String into a Number of Sub-Strings In this article, we will learn how to split a string into a number of sub-strings using the C program.The most straightforward method to split a string into substrings using a delimiter is by using strtok() function. Letâs take a look at an example:C#include <stdio.h> #include <string.h> 3 min read Program that allows integer input only Given an input value N, the task is to allow taking only integer input from the user. Now, if the user enters any input other than an integer, that is, a character or symbol, it will not be accepted by the program. Below is the C program to implement this approach: C // C program for the above appro 3 min read C Program to Sort an Array in Ascending Order Sorting an array in ascending order means arranging the elements in the order from smallest element to largest element.The easiest way to sort an array in C is by using qsort() function. This function needs a comparator to know how to compare the values of the array. Let's look at a simple example:C 3 min read How to Insert an Element into an Array of Structs at a Specific Position in C? In C, structs allow the users to create user-defined data types which can be used to store data of different types in a single unit. In many use cases, we might use an array of structs to store the structs in contiguous memory locations to access them sequentially. In this article, we will learn how 3 min read C Program to Traverse an Array in Reverse Write a C program to traverse a given array in reverse order that contains N elements.ExamplesInput: arr[] = {2, -1, 5, 6, 0, -3}Output: -3 0 6 5 -1 2Input: arr[] = {4, 0, -2, -9, -7, 1}Output: 1 -7 -9 -2 0 4Different Ways to Traverse an Array in Reverse Order in CWe can traverse/print the array in 2 min read How to Pass Array of Structure to a Function in C? An array of structures in C is a data structure that allows us to store multiple records of different data types in a contiguous memory location where each element of the array is a structure. In this article, we will learn how to pass an array of structures from one function to another in C. Passin 2 min read How to Find the Size of an Array in C? The size of an array is generally considered to be the number of elements in the array (not the size of memory occupied in bytes). In this article, we will learn how to find the size of an array in C.The simplest method to find the size of an array in C is by using sizeof operator. First determine t 2 min read Like