Anonymous
Can be only integer numbers
You should understand that part of being a programmer is to speak " english ", I know it might not be your native language, but don't expect to get help and you can't even write a decent explaination and example of input and output for the problem..
Shubh Joshi
man, I now see why I was non-stop bothered by teachers to name my variables properly instead of letters. I think if you just rewrite it properly, you should write it correctly. Right now ir looks more like a puzzle and I don't think anybody here can decode it, really.
Ohh...yeah got it🙏😇 Actually in problem solving...I am beginner.....I was thinking that what comments and variable names matters But today I got it😂🙏 I'll send with proper comments and effective variable name Once again thanks
SMS
Why is this?
x++ may generate a temporary variable, to represent the previous value of this variable. but in this case, it is the same. the compiler will take care of it
klimi
x++ may generate a temporary variable, to represent the previous value of this variable. but in this case, it is the same. the compiler will take care of it
i thought that compiler will optimize such thing. as it can optimize more complex things also... but yeah... maybe it is personal taste or something
Anonymous
Hello any expert in SAS programming?
ꍏꈤꀸ
Hi, how can i asynchronously call some function N times and get results? Here's what i tried with std::packaged_task, but i can' call it more than once: std::packaged_task packagedTask{ [] {} }; //packagedTask.get_future(); // way to get result afterwards packagedTask(); packagedTask(); // future_error - promise already satisfied *Note1: I want to control by myself when and where function is executed *Note2: I'm limited with C++ 11
Ludovic 'Archivist'
Евгений
First, learn how to Google, bro:)))
Anonymous
Can someone help to place comments. #include <iostream> #include<string> using namespace std; class student { private: int id; string name; double marks[3]; public: void setid(int i) { id = i; } void setname(string n) { name = n; } void setmarks(student st []) { int sum; int ss; int i; for ( i = 0;i < 3;i++) { cin>> st[i].marks[0]; cin >> st[i].marks[1]; cin >> st[i].marks[2]; sum = st[i].marks[0]; sum = st[i].marks[1]; sum = st[i].marks[2]; } ss = sum; } int getid() { return id; } string getname() { return name; } double* getmarks() { return marks; } student(int ii, string nn, const double mm[3]) { id = ii; name = nn; int j; for ( j = 0; j < 3; j ++) { cin >> mm[j]; } marks[j] = mm[j]; } student() { cout << "stident marks" << endl; } double avg() { return ss / 3; } void print() { cout << "id = " << id << endl; cout << "name = " << name << endl; for (size_t i = 0; i <3; i++) { cout << "marks = "<<marks[i] << endl; } cout << "avg = " << ss << endl; } }; int main() { student s2; student s1[3]; for (size_t i = 0; i <3; i++) { } }
klimi
place comments? if you have written the code, you should be able to say what it does
Anonymous
place comments? if you have written the code, you should be able to say what it does
I think he is asking for feedback (comments on the coding style) and stuff.
Евгений
Can someone help to place comments. #include <iostream> #include<string> using namespace std; class student { private: int id; string name; double marks[3]; public: void setid(int i) { id = i; } void setname(string n) { name = n; } void setmarks(student st []) { int sum; int ss; int i; for ( i = 0;i < 3;i++) { cin>> st[i].marks[0]; cin >> st[i].marks[1]; cin >> st[i].marks[2]; sum = st[i].marks[0]; sum = st[i].marks[1]; sum = st[i].marks[2]; } ss = sum; } int getid() { return id; } string getname() { return name; } double* getmarks() { return marks; } student(int ii, string nn, const double mm[3]) { id = ii; name = nn; int j; for ( j = 0; j < 3; j ++) { cin >> mm[j]; } marks[j] = mm[j]; } student() { cout << "stident marks" << endl; } double avg() { return ss / 3; } void print() { cout << "id = " << id << endl; cout << "name = " << name << endl; for (size_t i = 0; i <3; i++) { cout << "marks = "<<marks[i] << endl; } cout << "avg = " << ss << endl; } }; int main() { student s2; student s1[3]; for (size_t i = 0; i <3; i++) { } }
Bro, no need to come here and ask what you can find on Google in one second. Don't make a mess, please. Sometimes people send so god damn difficult questions that other people think days or weeks to solve the problem. But you're code is nothing but a text from Google lessons, please, read documentation carefully, maybe without music. Here's not a first degree school, bro.
D
double getNumbers() { double answer = 0.0; bool numbersGotten = false; int const SIZE = 3; double numbers[SIZE]; int i = 0; // Input - Numbers cout << "\nEnter three numbers separated by a space: "; for (i = 0; i < SIZE; i++) { cin >> numbers[i]; } answer = numbers[i]; return answer; } double add() { int i = 0; int const SIZE = 3; double numbers[SIZE]; double answer = 0; // Calculation answer = numbers[0]; for (i = 1; i < SIZE; i++) { answer += numbers[i]; } // Output cout << "\nAnswer: " << answer << ", i.e., "; cout << numbers[0]; for (i = 1; i < SIZE; i++) { cout << " + " << numbers[i]; } cout << "\n"; answer = numbers[i]; return answer; } can someone please help me , i want to know how can i get the values i inputed in the first function and place them in the second function in order to perform the addition thanks
Anonymous
.?
Could be because of the allocation of array cs on stack. Sometimes stack memory allocated by default is on the lower side and maybe that is why your code is getting a segmentation fault.
Anonymous
What should I do to avoid it? And why it is running online 😅
Probably because your online platform implementation allocates a bigger stack size by default. Check how to change stack sizes on the platform you are developing on
Anonymous
Ok I'll look this Thanks 👍
Runs fine on mine, Try using std::cout for debugging
Anshul
Probably because your online platform implementation allocates a bigger stack size by default. Check how to change stack sizes on the platform you are developing on
If I increase max stack size, it will only impact the size of program or it'll also impact time to execute
Anshul
Just use std::vector
But I already wrote "using namespace std"😕
Anshul
But I am using more stack memory then why doesn't it affect anything
Anshul
If it won't affect then why isn't it kept a larger value already😐
Anonymous
But I am using more stack memory then why doesn't it affect anything
If you tell the OS that you need more stack memory than you use, it will not affect the run time. The OS will not map unusued pages to physical memory until they are needed.
Anonymous
If it won't affect then why isn't it kept a larger value already😐
Because it will be a problem with multithreaded programs where each thread has a separate stack. So OS implementers choose a reasonable default.
klimi
I think he is asking for feedback (comments on the coding style) and stuff.
🤦‍♂️alright that would actually make some sense
.......................
Please help with this problem Consider the following program in C++11/14 to compute the product of a number of elements. Fill in the blanks as per the instructions given below: • at LINE-1 with appropriate periodic template for function product, • at LINE-2 with appropriate body of the product function, such that it will satisfy the given test cases. Select the Language for this assignment. C++ 1 #include <iostream> 2 ​ 3 template <typename T> 4 double product(T num){ return num; } 5 ​ 6 ________ //LINE-1 7 ​ 8 double product(T num, Tail... nums){ 9 ​ 10 ________; //LINE-2 11 } 0 int main(){ 1 int a, b; 2 double c, d; 3 std::cin >> a >> b >> c >> d; 4 std::cout << product(a, b) << std::endl; 5 std::cout << product(c, d) << std::endl; 6 std::cout << product(a, b, c, d) << std::endl; 7 return 0; 8 }
Tate
Hello need help with a question if anyone can help
Tate
Write a C program that creates a function bitFlip() that takes an int parameter and returns an int that has all of the int that was passed in bits flipped. It changes all 0s to 1s and all 1s to 0s. In the main function, read in an int num using scanf, call bitFlip(), and the function returns num with its bits flipped.
Евгений
It's easy, bro. Just Google bitwise operations
Emran Hasan
Which app is best for c coding? For Android 🙏
Tate
It's easy, bro. Just Google bitwise operations
New to c so really been trying to work some questions 😂, hard when you are alone
Евгений
Learncpp.com
Евгений
Very good arranged, i guess it's chapter 6, or O, not zero, bro.
Anonymous
Any programmer available... I need one for my startup
paper
Write a C program that creates a function bitFlip() that takes an int parameter and returns an int that has all of the int that was passed in bits flipped. It changes all 0s to 1s and all 1s to 0s. In the main function, read in an int num using scanf, call bitFlip(), and the function returns num with its bits flipped.
The & (bitwise AND) in C or C++ takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1. The | (bitwise OR) in C or C++ takes two numbers as operands and does OR on every bit of two numbers. The result of OR is 1 if any of the two bits is 1. The ^ (bitwise XOR) in C or C++ takes two numbers as operands and does XOR on every bit of two numbers. The result of XOR is 1 if the two bits are different. The << (left shift) in C or C++ takes two numbers, left shifts the bits of the first operand, the second operand decides the number of places to shift. The >> (right shift) in C or C++ takes two numbers, right shifts the bits of the first operand, the second operand decides the number of places to shift. The ~ (bitwise NOT) in C or C++ takes one number and inverts all bits of it
paper
Which app is best for c coding? For Android 🙏
Any app that can compile c and has an editor. But really, avoid coding on your phone this is bad practice...
🙋🏻‍♂️
Guys
🙋🏻‍♂️
Can anyone tell me what a state machine is?
Anonymous
You are given a 3x3 matrix of positive integers. You have to determine whether some row is a positive integer multiple of another. If row i is an integer multiple of row j, then you have to output p#q where p is the minimum of (i,j) and q is the maximum of (i,j). If there are multiple possibilities for i and j, you have to print for the smallest i and the smallest j. Otherwise, you have to output 0#0
Anonymous
for int i=1;i<=3;i++{ for int j=1;j=<3;j++{ if (i*j)%j=0 printf ("p#q") else printf("0#0"); } }
Peace
how to increment int value of vector of pairs ? vector<pair<string,int>> ques; like below : for(auto row: questions){ row.second++; }
Anshul
https://pastebin.com/hjC5LHRb in this code when i run it on leetcode i am getting runtime error but on my machine it runs fine
Anshul
================================================================= ==31==ERROR: AddressSanitizer: heap-use-after-free on address 0x603000000048 at pc 0x000000373c45 bp 0x7ffc207b46f0 sp 0x7ffc207b46e8 READ of size 8 at 0x603000000048 thread T0 #3 0x7fbe19e7c0b2 (/lib/x86_64-linux-gnu/libc.so.6+0x270b2) 0x603000000048 is located 8 bytes inside of 24-byte region [0x603000000040,0x603000000058) freed by thread T0 here: #4 0x7fbe19e7c0b2 (/lib/x86_64-linux-gnu/libc.so.6+0x270b2) previously allocated by thread T0 here: #4 0x7fbe19e7c0b2 (/lib/x86_64-linux-gnu/libc.so.6+0x270b2) Shadow bytes around the buggy address: 0x0c067fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c067fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c067fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c067fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c067fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =>0x0c067fff8000: fa fa fd fd fd fa fa fa fd[fd]fd fa fa fa 00 00 0x0c067fff8010: 00 fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c067fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c067fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c067fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c067fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb Shadow gap: cc ==31==ABORTING this is the error message
Anonymous
Please identify mistake i might have done here #include <iostream>  //  using namespace std;  //  class Object //Abstract class in C++  {  public :  void show () = 0; //pure virtual function   };  //  class ArithmeticAdd : public Object   {  int res;  public:  void add (int a, int b) {  res = a + b ;  }  void add (int a, int b, int c) // Function overloading - Static Binding   {  res = a + b + c;  }  void show () {  cout << "Result = " << res;  }  };  //  class Complex : public Object   {  int real;  int img;  public :  Complex Add (Complex C1, Complex2) {  real = C1.real + C2.real;  img = C1.img + C2.img;  return this;  }  void show () {  cout << real << " + " << img << "i" <<endl;  }  friend istream & operator >> (istream &, Complex &); // Friend functions and operator overloading   };  //  istream & operator >> (istream & in, Complex & c)   {  in >> c.real >> c.img;  return in;  }  //  int main ()   {  Object o [2];  ArithmeticAdd a;  a.add (2,6);  o [0] = &a;  o [0].show (); // Dynamic dispatch - run time polymorphisms   a.add (9,11,23);  o [0].show ();  Complex C1, C2, C3, C4;  cin >> C1;  cin >> C2;  C4 = C3.Add (C1, C2); // Message passing   o [1] = & C4;  o [1].show ();  return 0;  } 
Anshul
https://pastebin.com/hjC5LHRb in this code when i run it on leetcode i am getting runtime error but on my machine it runs fine
the question here is to trim a bst and make all values in the range given [low,high] the algorithm that i try to implement is: i will traverse all nodes and if for a particular node the value is either lesser than low or higher than high, i will delete that node from bst. at the end i will be only left with the desired nodes But i still get some errors in this approach, can anyone help me find why?
Anshul
Please identify mistake i might have done here #include <iostream>  //  using namespace std;  //  class Object //Abstract class in C++  {  public :  void show () = 0; //pure virtual function   };  //  class ArithmeticAdd : public Object   {  int res;  public:  void add (int a, int b) {  res = a + b ;  }  void add (int a, int b, int c) // Function overloading - Static Binding   {  res = a + b + c;  }  void show () {  cout << "Result = " << res;  }  };  //  class Complex : public Object   {  int real;  int img;  public :  Complex Add (Complex C1, Complex2) {  real = C1.real + C2.real;  img = C1.img + C2.img;  return this;  }  void show () {  cout << real << " + " << img << "i" <<endl;  }  friend istream & operator >> (istream &, Complex &); // Friend functions and operator overloading   };  //  istream & operator >> (istream & in, Complex & c)   {  in >> c.real >> c.img;  return in;  }  //  int main ()   {  Object o [2];  ArithmeticAdd a;  a.add (2,6);  o [0] = &a;  o [0].show (); // Dynamic dispatch - run time polymorphisms   a.add (9,11,23);  o [0].show ();  Complex C1, C2, C3, C4;  cin >> C1;  cin >> C2;  C4 = C3.Add (C1, C2); // Message passing   o [1] = & C4;  o [1].show ();  return 0;  } 
what is the error that you're getting
Anshul
#include <iostream> // using namespace std; // class Object //Abstract class in C++ { public : void virtual show() = 0; //pure virtual function }; // class ArithmeticAdd : public Object { int res; public: void add (int a, int b) { res = a + b ; } void add (int a, int b, int c) // Function overloading - Static Binding { res = a + b + c; } void show () { cout << "Result = " << res; } }; // class Complex : public Object { int real; int img; public : Complex Add (Complex C1, Complex C2) { real = C1.real + C2.real; img = C1.img + C2.img; return *this; } void show () { cout << real << " + " << img << "i" <<endl; } friend istream & operator >> (istream &, Complex &); // Friend functions and operator overloading }; // istream & operator >> (istream & in, Complex & c) { in >> c.real >> c.img; return in; } // int main () { //Object o [2]; ArithmeticAdd a; a.add (2,6); //o [0] = &a; //o [0].show (); // Dynamic dispatch - run time polymorphisms a.add (9,11,23); //o [0].show (); Complex C1, C2, C3, C4; cin >> C1; cin >> C2; C4 = C3.Add (C1, C2); // Message passing //o [1] = & C4; //o [1].show (); return 0; }
Munir
hello Anyone who have W3schools full access account for sharing ?
Anshul
1. in show, you need to mention it is a virtual function by using virtual keyword 2. you can't return "this" as Complex 3. Object is an abstract class, so you can't create it's object
Anonymous
what is the error that you're getting
Have try to run but it can't
Shubh Joshi
Hello coders I want to print 10^9 in c++ I have tried to find it on Google and I get something. But still I am facing some problem So please help me.... suggest easiest way to print that type of very big number Thanks in advance 👍
Shubh Joshi
Sorry...but I want to print 10 digit number....which user will input Not only 10 to the power
Shubh Joshi
Kavy thanks From double...I hv done it🙌👍👍
Kavy
https://youtu.be/xCR6TrfFSao
|▪️𝕋𝕆ℕ𝕐 𝕊𝕋𝔸ℝ𝕂 ▪️|
You are given a sequence of positive numbers terminated with a -1. Some initial portion of the sequence is monotone non-decreasing. You can assume that the non-decreasing part has at least 2 elements and the part after that also has at least one element. The first element starts at index 0. You have to output the index i which represents the end of the monotone non-decreasing part. You can refer to the public inputs and outputs for clarification.
|▪️𝕋𝕆ℕ𝕐 𝕊𝕋𝔸ℝ𝕂 ▪️|
can i get solution to this
Lombord
Hi guys
I
Hello. Can anyone help me with this line of code that casts void* as char**, I can't find anything about it: char **dynamic_str_1 = (char **)malloc(sizeof(char) * 8); what the heck is going on here?