а
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
Tazin
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 💜
touhou
DaviChan
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
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
Gain
Jose
Read the code as if you didn't write it and you will understand it
mito
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.
Gain
Gifty
Is there anyone who will help me tomorrow 10am
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
Anjana
Hey everyone
Anjana
I am new here
Anjana
I want to learn c++
Anjana
Ya read
Anjana
Then what is this for ?
Anjana
Here also I can learn right
N
后藤
how can i compile cpp program on ipad locally?
Vlad
Vlad
Only for 4.95$
klimi
oh simple question, you first analyze the problem and then you write the code
mito
Vlad
Doubt that it supports cmake and such
Edward
后藤
后藤
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?
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;
}
Anonymous
Anonymous
Anonymous
i also tried to do it that way
Anonymous
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
klimi
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.