Skip to content

Instantly share code, notes, and snippets.

@Bibekdhkl
Created March 14, 2021 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bibekdhkl/bc2fb136b6e61073c0391424b0c4147b to your computer and use it in GitHub Desktop.
Save Bibekdhkl/bc2fb136b6e61073c0391424b0c4147b to your computer and use it in GitHub Desktop.
TEST problem need help in managing memory
/*
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