Anonymous
Then why does it need allocation and deallocation?
Because of the fact that they are mutable. So if you do an operation that increases the size of the string, how can you do it without allocating more memory?
Anonymous
#include<stdio.h> int main(){ int num; printf("Enter the number: "); scanf("%d",&num); if(num==0) { printf("your number is zero" ); } else if(num>0) { if(num%2==0); { printf("your number is positive and even"); } else { printf(" your number is positive and odd"); } } else { if(num%2==0); { printf(" your number is negative and even"); } else{ printf("your number is negative and odd"); } } }
Anonymous
Hello help me
MuchubaTactics
Mustapha
Good Aswin
Anshul
https://pastebin.com/kaS0N8mf
Anshul
please go through this and help me find why this error
Mustapha
Anshul
It has an error
What's it
Talula
What's it
#include<stdio.h> int main() { int num; printf("Enter the number: "); scanf("%d",&num); if(num==0) printf("your number is zero" ); else if(num>0) if(num%2==0) printf("your number is positive and even"); else printf(" your number is positive and odd"); else if(num%2==0) printf(" your number is negative and even"); else printf("your number is negative and odd"); }
Talula
What's it
Semicolon after if statement without executing any additional function.
Олександр
if (i & (1 << j)) Hi, please explain me what does the sign "<<" mean and how does it work practically
Anshul
That's very easily available
Олександр
Ok, thanks
Mustapha
Yea I missed that
Now you know where the mistake is
Mustapha
But try runing it again
Jasur Fozilov 🐳
#include <bits/stdc++.h> using namespace std; int main(){ pair<int,int> divide_remainder(int dividend, int divisor); auto [fraction,remainder]=divide_remainder(16,3); cout<<"16/3 is "<<fraction<<" with a remainder of "<<remainder; }
Jasur Fozilov 🐳
I have took the following error: class.cpp: In function ‘int main()’: class.cpp:7:10: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ 7 | auto [fraction,remainder]=divide_remainder(16,3); | ^ /usr/bin/ld: /tmp/ccClwMwh.o: in function `main': class.cpp:(.text+0x26): undefined reference to `divide_remainder(int, int)' collect2: error: ld returned 1 exit status
olli
how can I compile c++17 mode ? I use visual stuido code
When compiling via VS code there might be a tasks.json file which specifies the arguments and compiler used, you should be able to add it there
Mustapha
can anyone help me ?
Okay let me run it
Anshul
I was talking about c++
Jasur Fozilov 🐳
Okay let me run it
you can run it freely
Jasur Fozilov 🐳
Okay let me run it
Have you tried ?
Anshul
It's not in c++
Anshul
But I thought it is. I was wrong
Anonymous
Hi all, Need assistance here, I'm trying to use this formula in my code, bmi=(w/h^2) and when compiling I'm getting an error "invalid operands of type float and int to binary operator^", I declared w, h and bmi as float.
artemetra 🇺🇦
artemetra 🇺🇦
^ is a binary XOR/EOR not OR. Binary OR is |
oh woops, read it wrong on google, fixed the message now
Mustapha
Have you tried ?
Yeah but still there is error in it and i can't fix it
Sam
#include<stdio.h> #include<stdlib.h> struct node struct node *head; { int data; struct node *next; }; void begininsert(); void display(); void main() { int choice = 0; while(choice >3){ printf("enter choice\n 1. begin insertion\n 2. display\n 3. exit\n enter your choice") scanf("%d",&choice); switch (choice){ case 1: begininsert(); break; case 2: display(); break; case 3: exit(0); break; default: printf("please enter a valid choice"); } } void begininsert(){ struct node *ptr; int item; ptr = (struct node*)malloc(sizeof(struct node*)); if(ptr == NULL){ printf("OVERFLOW"); } else{ printf("insert value:\n"); scanf("&d",&item); ptr->data = item; ptr->next = head; head = ptr; printf("\nnode inserted"); } } void display(){ struct node *ptr; ptr = head; if (ptr == NULL){ printf("there is nothing to print"); } else{ printf("the inserted values are :"); while(ptr != NULL){ printf("%d",ptr ->data); ptr = ptr->next;} } } }
Sam
can anyone help with the error in this code
Anonymous
#include <iostream> #include <cstdlib> #define MAX_VALUE 65536 using namespace std; class N { //node declaration public: int k; N *l, *r; bool leftTh, rightTh; }; class ThreadedBinaryTree { private: N *root; public: ThreadedBinaryTree() { //constructor to initialize the variables root= new N(); root->r= root->l= root; root->leftTh = true; root->k = MAX_VALUE; } void makeEmpty() { //clear tree root= new N(); root->r = root->l = root; root->leftTh = true; root->k = MAX_VALUE; } void insert(int key) { N *p = root; for (;;) { if (p->k< key) { / /move to right thread if (p->rightTh) break; p = p->r; } else if (p->k > key) { // move to left thread if (p->leftTh) break; p = p->l; } else { return; } } N *temp = new N(); temp->k = key; temp->rightTh= temp->leftTh= true; if (p->k < key) { temp->r = p->r; temp->l= p; p->r = temp; p->rightTh= false; } else { temp->r = p; temp->l = p->l; p->l = temp; p->leftTh = false; } } bool search(int key) { N *temp = root->l; for (;;) { if (temp->k < key) { //search in left thread if (temp->rightTh) return false; temp = temp->r; } else if (temp->k > key) { //search in right thread if (temp->leftTh) return false; temp = temp->l; } else { return true; } } } void Delete(int key) { N *dest = root->l, *p = root; for (;;) { //find Node and its parent. if (dest->k < key) { if (dest->rightTh) return; p = dest; dest = dest->r; } else if (dest->k > key) { if (dest->leftTh) return; p = dest; dest = dest->l; } else { break; } } N *target = dest; if (!dest->rightTh && !dest->leftTh) { p = dest; //has two children target = dest->l; //largest node at left child while (!target->rightTh) { p = target; target = target->r; } dest->k= target->k; //replace mode } if (p->k >= target->k) { //only left child if (target->rightTh && target->leftTh) { p->l = target->l; p->leftTh = true; } else if (target->rightTh) { N*largest = target->l; while (!largest->rightTh) { largest = largest->r; } largest->r = p; p->l= target->l; } else { N *smallest = target->r; while (!smallest->leftTh) { smallest = smallest->l; } smallest->l = target->l; p->l = target->r; } } else {//only right child if (target->rightTh && target->leftTh) { p->r= target->r; p->rightTh = true; } else if (target->rightTh) { N *largest = target->l; while (!largest->rightTh) { largest = largest->r; } largest->r= target->r; p->r = target->l; } else { N *smallest = target->r; while (!smallest->leftTh) { smallest = smallest->l; } smallest->l= p; p->r= target->r; } } } void displayTree() { //print the tree N *temp = root, *p; for (;;) { p = temp; temp = temp->r; if (!p->rightTh) { while (!temp->leftTh) { temp = temp->l; } } if (temp == root) break; cout<<temp->k<<" "; } cout<<endl; } }; int main() { ThreadedBinaryTree tbt; cout<<"ThreadedBinaryTree\n";
Anonymous
char ch; int c, v; while(1) { cout<<"1. Insert "<<endl; cout<<"2. Delete"<<endl; cout<<"3. Search"<<endl; cout<<"4. Clear"<<endl; cout<<"5. Display"<<endl; cout<<"6. Exit"<<endl; cout<<"Enter Your Choice: "; cin>>c; //perform switch operation switch (c) { case 1 : cout<<"Enter integer element to insert: "; cin>>v; tbt.insert(v); break; case 2 : cout<<"Enter integer element to delete: "; cin>>v; tbt.Delete(v); break; case 3 : cout<<"Enter integer element to search: "; cin>>v; if (tbt.search(v) == true) cout<<"Element "<<v<<" found in the tree"<<endl; else cout<<"Element "<<v<<" not found in the tree"<<endl; break; case 4 : cout<<"\nTree Cleared\n"; tbt.makeEmpty(); break; case 5: cout<<"Display tree: \n "; tbt.displayTree(); break; case 6: exit(1); default: cout<<"\nInvalid type! \n"; } } cout<<"\n"; return 0; } Any one solution this problem
'''''''
also there's a missing semicolon after the first printf statement in main() function
'''''''
can anyone help with the error in this code
read here —> https://stackoverflow.com/questions/38430229/why-cant-we-define-function-inside-the-main-function so ur code —>https://hastebin.com/axomiguwuj.cpp
Gift
Hi
Anonymous
Hi
Hi
Anonymous
Some one who help in set and get function
Anonymous
🙏Please
Anonymous
Some one who help in set and get function
I think not, as you didn't provide a problem.
Ибраги́м
Use pastebin
Vikas
Use pastebin
Or ideone.com
your_averageVimmer
Wait I have a question
your_averageVimmer
Can you write a program to find factorial of 500 in C
Anonymous
Wait I have a question
type in the google search bar 'factorial of 500' and read the first result in bold
Anonymous
Wait I have a question
exceeds the value of a long double
olli
Can you write a program to find factorial of 500 in C
yes, using some big int library (e.g. gmp)
Anonymous
yes, using some big int library (e.g. gmp)
yes, the only solution, but there is no built-in support in a language for such large numbers
Anonymous
yes, the only solution, but there is no built-in support in a language for such large numbers
Why would there be? C and C++ still stick to their roots of being as close to the machine as possible. Any new feature that is added is only done so if it has zero cost abstraction. Now there is no way to support an arbitrary precision number with zero cost abstraction. So this feature may never make it to the standard
Anonymous
Can you write a program to find factorial of 500 in C
If you can solve it mathematically and you have enough resources, yes
Mustapha
#include<stdio.h> #include<stdlib.h> struct node; struct node *head; int void; { struct node *next; void begininsert(); void display(); void main(); { int choice = 0; while(choice >3){ printf("enter choice\n 1. begin insertion\n 2. display\n 3. exit\n enter your choice") scanf("%d",&choice); switch (choice){ case 1: begininsert(); break; case 2: display(); break; case 3: exit(0); break; default: printf("please enter a valid choice"); } } void begininsert(){ struct node *ptr; int item; ptr = (struct node*)malloc(sizeof(struct node*)); if(ptr == NULL){ printf("OVERFLOW"); } else{ printf("insert value:\n"); scanf("&d",&item); ptr->data = item; ptr->next = head; head = ptr; printf("\nnode inserted"); } } void display(){ struct node *ptr; ptr = head; if (ptr == NULL){ printf("there is nothing to print"); } else{ printf("the inserted values are :"); while(ptr != NULL){ printf("%d",ptr ->data); ptr = ptr->next;} } } }
Shahar
union Cars { char make[20]; char model[30]; short year; } car; Can someone explain why the size of this union is 30 bytes?
Anonymous
union Cars { char make[20]; char model[30]; short year; } car; Can someone explain why the size of this union is 30 bytes?
The union is only as big as necessary to hold its largest data member. The other data members are allocated in the same bytes as part of that largest member. https://en.cppreference.com/w/cpp/language/union
Anonymous
model 30
Shahar
model 30
Suppose model uses all its 30 bytes. Now, make and year want to use also some amount of bytes for their own purposes. But they would overwrite the bytes of model
Anonymous
it may be true, try it
Vikas
If I initialise an int variable with value 2 the how many bits will it use?
Vikas
Will it be 2 bits or 32 bits? Because 2 is written as 10(two bits)
Anonymous
32 bits