-
-
Save Bibekdhkl/bc2fb136b6e61073c0391424b0c4147b to your computer and use it in GitHub Desktop.
TEST problem need help in managing memory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
TEST - Life, the Universe, and Everything | |
#basic #tutorial #ad-hoc-1 | |
Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits. | |
Example | |
Input: | |
1 | |
2 | |
88 | |
42 | |
99 | |
Output: | |
1 | |
2 | |
88 | |
Information | |
In case of any problems with your code, you can take a look in the forum, you'll find the answer, only for this problem, in various languages. | |
*/ | |
#include<stdio.h> | |
int main(){ | |
int arr[1000],i=0,n=0; | |
do{ | |
scanf("%d",&arr[i]); | |
i++; | |
n++; | |
}while(arr[i-1]!=42); | |
for(i=0;i<(n-1);i++){ | |
printf("%d\n",arr[i]); | |
} | |
return 0; | |
} | |
/* | |
Question frome me is: | |
1)How can I manage memory properly? | |
like Is it possible to make value to store dynamically as long as user enters 42??? | |
2) What might be the best possible way to solve this problem??? | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment