answersLogoWhite

0


Best Answer

You can use dynamic arrays. Malloc, realloc and free play crucial roles. You can also substitute calloc for malloc. Below is a sample code:

#include


#include



int

main(){
int

n = 10

, noofnumbers = 0

, num, i;

int

*arr = (

int

*)malloc(n*

sizeof

(

int

));

//first creating an array of size 10 - you can even skip this part and directly go for expanding an array every time an element is entered
if

( !arr ){
printf(

"No space in memory\n");


return

(1

);
}
while

( scanf("%d"

, &num) != EOF){
if

( noofnumbers < n){
arr[noofnumbers] = num;
noofnumbers++;
}

else

{

//when more than 10 numbers are added increasing the size accordingly
int

*temp = (int

*) realloc(arr, (++n)*sizeof

(int

));//realloc for reallocating the memory
if

( temp == NULL

){
printf("Not enough space\n"

);
break

;
}
else

{
arr = temp;
arr[noofnumbers] = num;
noofnumbers++;
}
}
}
printf(

"the numbers are:\t");


for

( i = 0

; iprintf("%d\t"

, arr[i]);
printf("\n"

); free(arr);//freeing the memory space
return

0

;

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you store a number of integers entered by the user in an arra with C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write Algorithm to perform the insertion and deletion operation of a linear array?

//Algorithm to perform the insertion and deletion operation of a linear arrayINSERT (ArrA, n, i, item) where ArrA is a linear array with n elements and i is a positive integer where i &lt;=n. The element 'item' will be inserted into the ith position in ArrA.1. j = n2. repeat steps 3 and 4 while j &gt;= i3. ArrA[j+1] = ArrA[j]4. j = j - 15. ArrA[i] = item6. n = n+1DELETE (ArrA, n, i, item) where ArrA is a linear array with n elements and i is a positive integer where i &lt;=n. The element 'item' will be deleted from the ith position in ArrA.1. item = ArrA[i]2. repeat for j = i to n -1 ArrA[j] = ArrA[j+1]4. n = n - 1NO HARD RETURNS ALLOWED


What has the author Carl Arra written?

Carl Arra has written: 'Physical education in the elementary school' -- subject(s): Physical education for children


What does the word arra mean in Korean?

It means "I know" or "I understand"


Is the stimulus bill the same as the American Recovery and Reinvestment Act of 2009?

yes the American recovery and reinvestment act (ARRA) is the same thing as the stimulus package. the (ARRA) is the real name.


How do you say money in Irish?

"airgead" - pronounced 'arra-gid' literally meaning silver


What is the meaning of tiobraid arann?

It means "The well of Arra" in old Gaelic and is the name of the town of Tipperary in Ireland.


How long to drive from cork city to killarney?

Arra not very long, its about an hour and 15 minutes driving time.


What is Tipperary in Irish?

In Irish Tipperary is Tiobraid &Atilde;&#129;rann. It means 'The Well of the Arra' - a reference to the river which flows through the town of Tipperary.


Cobra sent me a letter telling me that I qualify for assistance of reduction in Cobra premiums, because I am 23 year old and I lost my Ins. with Cigna I need to fillout those ARRA forms How I get Them?

I believe these are the forms you are looking for. They can be downloaded and printed out via pdf (Adobe). There are links to instructions there also. ARRA forms are located right at the top of the list. http://www.discoverybenefits.com/forms.aspx Here also is a link to the Cobra ARRA FAQs page; http://www.discoverybenefits.com/faq.aspx?permalink=347 If these links dont give you the exact answer you are looking for you can call Discovery Benefits COBRA Continuant Services at 866-451-3399, option 1 for more information.


What is ARRA Certification?

The Health Information Technology for Economic and Clinical Health (HITECH) Act is part of the economic stimulus package (ARRA) passed by the US Congress and signed into law on February 17, 2009. One of the HITECH Act's primary goals is to encourage the adoption and use of Electronic Health Records. Provisions in the Act allow eligible providers to gain incentive dollars for the meaningful use of an electronic health record.


What is the total amount of power generated by wind turbines in Australia?

judf sf sdc c gyug weOeg fyv uy vuyr vu r ruey e auare u ra arra rfafyvfrfrv rfv


What are some four letter palidromes?

abba, anna, arra, boob, deed, ecce, egge, elle, emme, erre, esse, kook, level, naan, neen, noon, obbo, oppo, otto, peep, poop, sees, teet, toot.