asked    Gustave     2018-10-22       c       126 view        1 Answer

[SOLVED] Should I include both fflush(stdin) and a space in scanf() or will only one of them suffice?

This question already has an answer here:

  1 Answer  

        answered    Sophia     2018-10-22      

fflush(stdin) is undefiined behavior.

int fflush(FILE *ostream);

ostream points to an output stream or an update stream in which the most recent operation was not input, the fflush function causes any unwritten data for that stream to be delivered to the host environment to be written to the file; otherwise, the behavior is undefined.





Your Answer





 2018-10-22         Woodrow

Making a matrix in python 3 without numpy using inputs

I want to have two inputs : a,b or x,y whatever...When the user inputs say,3 5Then the shell should print a matrix with 3 rows and 5 columns also it should fill the matrix with natural numbers( number sequence starting with 1 and not 0).Example:: IN :2 2OUT:[1,2] [3,4] If your objective is only to get the output in that formatn,m=map(int,input().split())count=0for _ in range(0,n): list=[] while len(list) > 0 : list.pop() for i in range(count,count+m): list.append(i) count+=1 print(list) [XXX]I am going to give a try without using numpy...
 python-3.x                     3 answers                     55 view
 2018-10-22         Rex

Why assigning a function as variable is faster in Python

Today I observed an interesting behavior using Python.def f(): ls1 = [] for x in range(1000000): ls1.append(x)%timeit f()77.2 ms ± 1.83 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)And tested a second function.def f2(): ls1 = [] lsa = ls1.append for x in range(1000000): lsa(x) %timeit f2()56 ms ± 566 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)Assigning append to a variable was faster than using append inside the loop.Why the second function is faster? Because in the second function, you have the reference to the m...
 python-3.x                     2 answers                     59 view
 2018-10-22         Rock

Please clarify my mistake while doing the dry run

The following code is all correct but I have a doubt. While I am doing the dry run I find in my mind that it should show 2 as NOT a prime number. Someone please clarify how the code is running all good. num = 4if num > 1: for i in range(2,num): if (num % i) == 0: print(num,"is not a prime number") print(i,"times",num//i,"is",num) break else: print(num,"is a prime number")else: print(num,"is not a prime number") 2 is a prime number, but your code will shows 2 as not a prime numberHere is the fix:num = 4if num > 2: fo...
 python                     1 answers                     55 view