Click here to Skip to main content
15,173,340 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have to write a program using one dimensional array with random elements that have the size of m (m is taken from the keyboard). The value of the array must be written in a txt file. How do I do that?

What I have tried:

i have tried to create the array but i can't.
Posted
Updated 22-May-21 7:16am
Comments
Patrice T 22-May-21 12:12pm
   
Show your work.

C++
int m;
scanf("%d", &m);
int array[m]; // create a one-dimensional array of 21 integers
// from here you can create a loop that adds randome values to each element
   
v2
Comments
Patrice T 22-May-21 12:13pm
   
"that have the size of m (m is taken from the keyboard)"
It is dynamic size.
Richard MacCutchan 22-May-21 12:15pm
   
Thank you, fixed.
Patrice T 22-May-21 12:22pm
   
my 5
Here is documentation for some functions that could be useful for this assignment :

calloc - C++ Reference[^]
rand - C++ Reference[^]
fopen - C++ Reference[^]
fprintf - C++ Reference[^]

I recommend that you read all of those pages and pay careful attention to the sample code.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900