Anonymous
So
Anonymous
Anonymous
Do i hv to learn basic of c++ to learn OOP
Mp
write a program with a function integral_sinus() which calculates integral with monte carlo methd
Mp
any one can help me?
Anonymous
no
Then what should i do
Anonymous
Can you just tell why you have used ptrfiif_t? and is it a pointer or array?
ptrdiff_t and size_t are good types for use as indices and sizes respectively. no problem with your unsigned int. https://en.cppreference.com/w/c/types/ptrdiff_t https://en.cppreference.com/w/c/types/size_t
Anonymous
learn oop
Thanks...
Anonymous
Ok thank
Can you help with one more
Anonymous
Perfectly valid code tbh
Write a program that will get all the prime numbers that were written before that number in the input. The numbers displayed must be separated by a space.
Anonymous
Anonymous
Anonymous
if (cout == K) ^^
#include <iostream> int main() { unsigned N,K; std::cin >> N>> K; int i = 1; int count = 0; while ( i <= N){ int x; std::cin >> x; if( x>=123){ count ++; } if (count == K) std::cout <<"YES"; else std::cout << "NO"; } }
Anonymous
if (cout == K) ^^
Maximum Run Time Exceeded
Anonymous
Can anyone help me
Anonymous
Ok
Anonymous
Somebody will respond
Anonymous
include <iostream> int main() { std::cout<<"5"; }
Anonymous
Purposely give a wrong answer to this one
Anonymous
Report back
Anonymous
Then let's test our algorithm itself, still keeping a wrong answer
Anonymous
#include <iostream> auto main() -> int { long i=0; int input=-1; for(int j=0;j<6;++j) { i+=j+1; } std::cout << i; }
Anonymous
This should put out 20
Anonymous
Now why we are giving a wrong answer Gagik
Anonymous
Very simple
Anonymous
How can you tell that the data is supplied after the program runs?
Anonymous
Im just learning
Anonymous
It can be an example of writing the arguments on the program's cmdline
Anonymous
We send wrong answers to test our algorithm first
Anonymous
Then we insert a blank cin to see if cin is the blocker
Anonymous
It might be that you need to parse arguments instead of user input
Anonymous
Ok 1 minute
Anonymous
I only took 5 lessons.l dont know much.and its hard for me to talk like that.
Anonymous
I will send the task again if ir is easy.plase write the correct code
Anonymous
It is required to write a program that will receive N և K non-negative integers at the input, then a sequence of N elements. The program must output "YES" as a result if the correct K of N numbers are greater than or equal to 123 և ‘NO’ otherwise. It is forbidden to use mass.
Anonymous
#include <iostream> int main() { unsigned N,K; std::cin >> N>> K; int i = 1; int count = 0; while ( i <= N){ int x; std::cin >> x; if( x>=123){ count ++; } if (count == K) std::cout <<"YES"; else std::cout << "NO"; } }
Anonymous
Write a program that gets a natural number N at the input, then a sequence of whole N elements. As a result, the program must display the difference between the largest and smallest elements of the sequence. It is forbidden to use mass.
Anonymous
what first
Anonymous
max and min?
Anonymous
Anonymous
i have no clue what this means
Anonymous
where i wrote it
Anonymous
ok
Anonymous
its and
Anonymous
klimi
What's mass?
klimi
Ic
Anonymous
#include <iostream> int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); unsigned int N, k, temp; std::cin >> N >> k; while (N-- != 0) { std::cin >> temp; if (temp >= 123) { --k; } } if (k) { std::cout << "NO\n"; } else { std::cout << "YES\n"; } }
Anonymous
there is no real problem with your code
Anonymous
idk what you can do to minimise time
Anonymous
you need to take input obviously
Anonymous
Ah @chandradeepdey now I know who G is
Anonymous
Thanks
Anonymous
std::ios::sync_with_stdio(false); you should write that in any C++ code where you won't use C style I/O (printf, scanf, getchar, fgets, puts, etc.) std::cin.tie(nullptr); only for competitive programming. (there are other reasons such as manually controlling when to flush output) search on google for the meaning of those two lines
Anonymous
do them yourself lmao. just see if they accept this one. you can add those two lines in front to reduce execution time of your other programs
Vitriol
/get cbook
Pavel
Maximum run time exceeded
Did you add std::cout << sum; at the end or just copypasted my code?
Pavel
you don't read N at the beginning, you should use it instead of 10 in the loop
Pavel
the same as you read x... it feels to me that you have no idea of what you're doing with this code
Martin
Just want to ask. is there any estimation for when C++ modules will be production ready?
Anonymous
indices can be negative though
Anonymous
though you are right, if the array has more than ptrdiff_t elements, this will lead to undefined behaviour
Shubham.JS
any one is free
Shubham.JS
i need help
Shubham.JS
I found some #isempty function error in cpp code pls
Anonymous
ye edited now
Anonymous
hi
Anonymous
#include <iostream> int main() { unsigned int a; std::cin >> a; int b; std::cin >> b; while(a<=b){ if (a%2==1) std::cout <<a<< " "; a++; } int i = 3; bool is_prime = true; while (i <= a/2) { if (a%i == 0) { is_prime = false; break; i+=2; } int g = 2; bool is_prime = true; while (g <= a/2) { if (a%g == 0) { is_prime = false; break; g+=1; } } } }