а
You can check this https://www.programiz.com/cpp-programming/examples/prime-number
labyrinth
i have a vector of unique ptr, is it safe to vec.emplace_back(std::make_unique<>)?
Alka
Three new health care buildings are to be built in HackerLand. They will be built on land with plots numbered consecutively starting from 1. There are two integer arrays starting, ending, each office n, that represent= n intervals where the ith interval is [starting[i], ending[i]]. Determine the number of ways three non-overlapping intervals can be selected from the n intervals.
Tazin
int main(){ int n; cout<<"Enter your number"<<endl; cin>>n; int originaln=n; int sum=0; while (n>0) { int last=n%10; sum+=pow(last,3); //pow hoilo power ber korar function. eta math.h header file e thake n=n/10; } if (sum==originaln) { cout<<"It's an armstrong"; } else{ cout<< "It's not armstong"; } return 0; }
Tazin
this is a programme to define if a number is a armstrong or not.
Tazin
but whatever i input it shows it's not armstrong even if i give an armstrong numbe
Tazin
where did I make mistake ?
Gain
assert(a >= 1 && b >= 1 && b <= 1e9 && a <= 1e9); can any1 tell me what this does?
Gain
where did I make mistake ?
what number did u input?
Gain
153
working on my machine
Tazin
Okayyy
Tazin
The pow function is the problem for my pc maybe
Tazin
When i simply multiplied them thrice then it worked
Tazin
Thank you so much 💜
DaviChan
toxic community. They hate everyone and call everyone a "paster".
Well that is because almost everyone there is a paster
DaviChan
Very few people are in to learn something. For me it was always about "what can i do"... that was fun. Not that i was better than someone else in the game. Never cared too mich about that. Ofc. i wanted to win also, but not through cheating. Also guided hacking had a good community. Most wandered off to other things. But some of the OGs are still connected on discord now
DaviChan
Ironicly what you see publicly is the worst community 😂.
DaviChan
Yes, with dynamically allocated memory. Are you using C or C++?
Rangarajan
Guys I am getting the below compile time error when I try to deserialize a particular object using boost library Error: "typex::value" inside check_const_loading() function in check.hpp file of boost library.. Can anyone help me??
DaviChan
Either way, in C you would do: void fn(size_t size){ int* arr = malloc(size*sizeof(int)); //work with the array free(arr); } in C++: auto fn(size_t size) -> void { auto vec{ std::vector<int>(size) }; /*use vec as if it was an array. for me i cant think of too many reasons to choose std::array over std::vector... so just use std::vector its a great default */ }
DaviChan
@AverageSicilianSfruttatore
DaviChan
make use of std::vector :). cppreference.com has good examples also on it
DaviChan
yes its part of the STL. use #include <vector> to use it
Gain
ll solve(){ ll n; ll zr=0; ll zb=0; ll r[n],b[n]; cin>>n; for(int i=0;i<n;i++){ cin>>r[i]; } for(int i=0;i<n;i++){ cin>>b[i]; } for(int i=0;i<n;i++){ if (zr>zb){ zb+=b[i]; }else{ zr+=r[i]; } } cout<<min(zr,zb)<<"\n"; return 0; } can anyone find any error?
Jose
Read the code as if you didn't write it and you will understand it
mito
What error do you get?
you have not initialised n but used it in r[n] and b[n] before asking for std::cin input for n. I don't know if that's the case.
mito
ll solve(){ ll n; ll zr=0; ll zb=0; ll r[n],b[n]; cin>>n; for(int i=0;i<n;i++){ cin>>r[i]; } for(int i=0;i<n;i++){ cin>>b[i]; } for(int i=0;i<n;i++){ if (zr>zb){ zb+=b[i]; }else{ zr+=r[i]; } } cout<<min(zr,zb)<<"\n"; return 0; } can anyone find any error?
I have used an online compiler. Run these two codes separately. Code 1: std::cin after a[n], b[n] #include <iostream> int main() { long long n; long long a[n], b[n]; std::cin >> n; std::cout << "Arrays Initialised :)" << std::endl; return 0; } Code 2: std::cin before a[n], b[n] #include <iostream> int main() { long long n; std::cin >> n; long long a[n], b[n]; std::cout << "Arrays Initialised :)" << std::endl; return 0; } One code works fine! The other gives segmentation fault. You can understand why it gives that if you look through the difference in the sequence of statements.
Gifty
Is there anyone who will help me tomorrow 10am
Pavel
Is there anyone who will help me tomorrow 10am
We don't help with cheating on exams, also 10am is different around the world
Anonymous
Windows?
N
I want to create a snake game project in C++(i don't want to copy code ) so what's the knowledge (i mean subtopics i know till pointers )required for it
N
Use atom
klimi
codeblocks
mito
I want to create a snake game project in C++(i don't want to copy code ) so what's the knowledge (i mean subtopics i know till pointers )required for it
If you're doing in cmd line then knowing any TUI library would help in creating an UI with cooler interfaces.
Anjana
Hey everyone
Anjana
I am new here
Anjana
I want to learn c++
klimi
I want to learn c++
then please read the rules of the group first
Anjana
Ya read
Edward
I want to learn c++
W3school is best tutorial
Anjana
Then what is this for ?
Anjana
Here also I can learn right
后藤
how can i compile cpp program on ipad locally?
Vlad
how can i compile cpp program on ipad locally?
There should some apps for that
Vlad
Only for 4.95$
后藤
Only for 4.95$
can it link to opencv libs?
klimi
oh simple question, you first analyze the problem and then you write the code
Vlad
can it link to opencv libs?
Probably but it will be a pain in the ass
Vlad
Doubt that it supports cmake and such
Edward
Ohh boi
What?
Vlad
can it link to opencv libs?
For that you'd probably need to jailbreak your ipad as well
后藤
i use ipad pro with m1 chip can it install macos?
后藤
i heard many people code with object c on macbook
Matija
solved it
Anonymous
#paste
Grigoriy
Hello. Should I be worried about performance overhead when I return a local variable of type std::list from function by value?
Pavel
Hello. Should I be worried about performance overhead when I return a local variable of type std::list from function by value?
It depends whether you return a list that was a local variable, or actually copy it. There's copy elision that works in some specific cases that can make it very cheap (similarly to NRVO). However, if the copy is actually performed then this can be very expensive, because copying a list requires allocating every element individually.
Anonymous
Hello. Should I be worried about performance overhead when I return a local variable of type std::list from function by value?
If you are returning it by value, then it will at best be RVO or NRVO or at worst it will be a move operation. So it won't be expensive in either case. However if the list you are assigning to has an allocator that is different from the allocator for the list used inside the function, then the move operation depends on the list element's move operations; and if this element does not have a move operation then a copy will be made. I guess you are not using different allocators and hence you wouldn't have to worry about this case.
Anonymous
int computeMax(int * array, int arrayLength) { // todo for(int i = 0; i < arrayLength - 1; i++) array[i]; for (int i = 1; i < arrayLength; i++) { if(array[i] < array[i+1]) { array[i] = array[i +1]; } } return 0; }
Pavel
this should be a C Program to Find Largest Element in an Array but its not working :3
To find the largest element in an array you need only one loop. Make a variable outside of the loop, assign something smaller than any of your elements can be to the variable. In the loop compare each element with this variable, and override the value whenever you find something bigger
Anonymous
i also tried to do it that way
Anonymous
Eugene
int computeMax(int * array, int arrayLength) { // todo int i, maxInt; maxInt=array[0]; for (i = 0; i < arrayLength - 1; i++) { if(array[i] > maxInt) { maxInt= array[i]; } } return maxInt; }
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Hi guys, so I have a C file named "main", and, among others, an h file named "server_standard_messages.h". The very first line of the server is "#include "server_standard_messages.h". Though, when I try and compile the whole thing on GCC WSL, GCC tells me "mex_name initialized and declared ‘extern' " Because, in the "server_standard_messages.h" file, every message is like this: extern char *mex_name= "stuff\n"; Now, I've been reading online that you use an extern when you need to extend the visibility of some stuff; basically, it's needed when a certain program in File A needs stuff from File B. Therefore I used extern, but now I'm starting to question wether it's really necessary or not. Could you please help me? Thx!
Adeyemo
Hello house I am Adeyemo, I am just starting out c programing please I would appreciate material/resources suggestions. I am self learning, and Also I'll love to have a mentor. Please help me climb up
Anonymous
Hi guys, so I have a C file named "main", and, among others, an h file named "server_standard_messages.h". The very first line of the server is "#include "server_standard_messages.h". Though, when I try and compile the whole thing on GCC WSL, GCC tells me "mex_name initialized and declared ‘extern' " Because, in the "server_standard_messages.h" file, every message is like this: extern char *mex_name= "stuff\n"; Now, I've been reading online that you use an extern when you need to extend the visibility of some stuff; basically, it's needed when a certain program in File A needs stuff from File B. Therefore I used extern, but now I'm starting to question wether it's really necessary or not. Could you please help me? Thx!
If it is a global variable that is not declared static or inline, then they have external linkage by default. The problem with your extern declaration is that it is also a definition because you provided an initialisation value. Now since this definition is in a header file, this definition is going to appear across multiple source files (translation units) that include this header file. Defining the same variable more than once in multiple translation units (barring a few exceptions) violates what is known as One Definition Rule (ODR) and will be flagged as an error when it can be detected. There are ways to get around this. 1. You can not initialize the extern variable in the header and instead initialize it in one and only one source file that includes the header file. 2. You can remove extern and declare the variable as either static (not recommended) or inline 3. You can remove extern and provide the definition within an anonymous namespace in the header file.