Sachin
no error but stop runing in between
4o4
but not working properly
I runned it and its workin
4o4
Yeah true
Sachin
At which point?
when i input price
Sachin
I runned it and its workin
can you share the screenshot plz
Dumb
It seems well done
GXUP320
use while(getchar() != '\n'); empty the stdin
GXUP320
fflush(stdin) cannot empty the buffer
Nameful
Windows
bro what
GXUP320
where
After scanf and gets
Sachin
'''''''
bro what
OS-windows
Anonymous
?
https://t.me/programminginc/401174
Anonymous
at best (Microsoft CRT library) fflush(stdin); is a no-op.
Anonymous
Hi
Anonymous
One of the problems I noticed is that in the merge function, you are initializing auxArrayIndex with leftLow. It should be 0. Not sure if there are other problems but this is definitely wrong because it will lead to Undefined Behavior as you will exceed the size of auxArray unless you fix this.
Anonymous
And for another problem, check what will happen if suppose you called your merge function with left = 2 and right = 4 say. If you fix those 2 problems, I think your algorithm would be ok. This can be fixed by changing the line where you are copying the aux array back to the main array from array[i] = auxArray[i] to array[i] = auxArray[i-left];
Anonymous
By reducing your code size. By dynamically linking libraries instead of using static libraries. Using OS system calls or maybe even the C library print functions instead of C++ standard library. Using the various optimization flags your compiler offers. Removing the debugging symbols from your executable
Abhi
https://pastebin.com/SAznbmgm
Abhi
Any one can help me with this Bubble sort algorithm
Abhi
It is not running
Shruti Debnath 376 Cse 25
//Finding the elements of the fibonacci series when user inputs no of elements of the series #include<stdio.h> void main() { int n1=0, n2=1, n3, num; printf("Enter number of elements of the fibonacci series"); scanf("%d", &num); for(int i=3; i<=num; i++) { n3=n1+n2; printf("%d ", n3); n1=n2; n2=n3; } }
Shruti Debnath 376 Cse 25
this is my code and the error: process killed because it took more than 10 seconds
Shruti Debnath 376 Cse 25
how can i get rid of this error?
Cris
how can i get rid of this error?
you are requesting user input with scanf, what number do you input? I ask because this works: #include<stdio.h> int main() { int n1=0, n2=1, n3, num; printf("Enter number of elements of the fibonacci series"); //scanf("%d", &num); // removed scanf num = 4; // fixed number to test the code for(int i=3; i<=num; i++) { n3=n1+n2; printf("\n%d ", n3); // added new line n1=n2; n2=n3; } return 0; } and prints: Enter number of elements of the fibonacci series 1 2
Cris
if you end up inputting a value for num, which is less than 3 (which is the value you initialize i with), the loop will unfold from 3 to the maximum representable number with an integer (which in you system it will probably be somewhere between 2pow32 and 2pow64), and then it will overflow, and start from 0 again. so TLDR; just check that the inputed number is not less than 3, and if possible I would challenge the start value of i, which I am not sure why starts from three (is it an assignment?)
Cris
you need to print N numbers from the fibonacci sequence, right? so that if I input, 10, it should output something like: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ...
@𝑺𝒐𝒃𝒌𝒂
Hi! I know include the string header is required to use string library. Why in some IDE as codeBlocks there is neither error nor warning when we don't include the header?
Anonymous
Hi! I know include the string header is required to use string library. Why in some IDE as codeBlocks there is neither error nor warning when we don't include the header?
Because those IDEs use what is called precompiled headers and most of the ones that are used regularly are automatically included for your convenience. Btw PCH has got nothing to do with this convenience. It is something that is done to save compilation time. You can disable this option.
Vlad
Given that you need them in the ascending order anyway
Vlad
Each value would be O(1) to compute
Cris
Sequence is easily calculated iteratively
yep, return n-1+n-2 when n>2
Vlad
yep, return n-1+n-2 when n>2
Nah this aint gonna cut it
Anonymous
//Finding the elements of the fibonacci series when user inputs no of elements of the series #include<stdio.h> void main() { int n1=0, n2=1, n3, num; printf("Enter number of elements of the fibonacci series"); scanf("%d", &num); for(int i=3; i<=num; i++) { n3=n1+n2; printf("%d ", n3); n1=n2; n2=n3; } }
The Fibonnacci series has 2 ones to begin with. And you are not printing the first n elements. You are printing n elements starting from the 2nd element. Fibonacci is an exponential series. So numbers grow very fast. Use an unsigned long long instead of int. What is the value of num for which you got Time Limit Exceeded.
Vlad
auto a = 0ULL; auto b = 1ULL; while(N--) { auto temp = a + b; std::swap(a, b); b = temp; }
Vlad
And just print temp lol
Anonymous
auto a = 0ULL; auto b = 1ULL; while(N--) { auto temp = a + b; std::swap(a, b); b = temp; }
even better https://github.com/lewissbaker/cppcoro#generatort
Anonymous
🏃💨
Shruti Debnath 376 Cse 25
N i added the printf statement for the 1st two nos after i noticed it😅
Shruti Debnath 376 Cse 25
what is the error?
It is taking a lot of time to print the statement "enter the number of elements of the fibonacci series"
Shruti Debnath 376 Cse 25
Around 6 secs in vs code
Shruti Debnath 376 Cse 25
N around 10 secs in that online gcc compiler
Cris
Nah this aint gonna cut it
//Fibonacci Series using Recursion #include<stdio.h> int fib(int n) { if (n <= 1) return n; return fib(n-1) + fib(n-2); } int main () { int n = 9; printf("%d", fib(n)); getchar(); return 0; } https://www.geeksforgeeks.org/program-for-nth-fibonacci-number/
Cris
This one isn't linear
I am mentioning this to explain what I meant before :)
Vlad
It takes exponential time to compute
Cris
so?
Vlad
so?
fib(32) would take 2^32 operations to complete
Cris
and?
Anonymous
and?
if you're saying to just compute a recursive fibonacci approach, it' OK, but it's only for someone who's starting out at recursion - "it ain't no free real estate" else, if you're gonna use recursion anyway, use dynamic programming
Cris
if you're saying to just compute a recursive fibonacci approach, it' OK, but it's only for someone who's starting out at recursion - "it ain't no free real estate" else, if you're gonna use recursion anyway, use dynamic programming
maybe I am missing the context, but I think I was answering to somebody having a problem with some (assignment?) code, so I assume the best way to help somebody who is trying to understand how to model a solution, is to show the easiest and "classical" way to do it
Anonymous
although using simple approach is better lol
Anonymous
but if the "assignment" is on recursion, without DP, you can't help it
Cris
just wanted to give a quick hand while I was waiting for a compilation to finish :D
Anonymous
N around 10 secs in that online gcc compiler
It is a problem on your system then. It works fine elsewhere