Manu
Whenever i try to take input ....it just show running in terminal
Ultima Filium
what's up people
Ultima Filium
how can assign the letters A to Z values of 1 to 26
Ultima Filium
such that A=1 and Z=26
'''''''
how can assign the letters A to Z values of 1 to 26
Define an enumerator starting from A to Z
Alessandro
such that A=1 and Z=26
Lookup ASCII codes
Ultima Filium
olli
Whenever i try to take input ....it just show running in terminal
in your run configuration you can try setting "externalConsole": true, this should make it open a console window for the application. In my experience that makes it easier to provide input
Mr
prog.cpp: In function ‘int NumberofElementsInIntersection(int*, int*, int, int)’: prog.cpp:27:14: error: expected primary-expression before ‘int’ map<int,int> ma(ma.begin(),ma.end()); ^ prog.cpp:29:13: error: ‘ma’ was not declared in this scope ma[b[j]]++; ^~ prog.cpp:32:23: error: ‘ma’ was not declared in this scope for ( auto j = ma.begin(); j != ma.end(); ++j) ^~ prog.cpp:40:14: error: expected primary-expression before ‘int’ map<int,int> m(m.begin(),m.end()); ^ prog.cpp:42:13: error: ‘m’ was not declared in this scope m[v[i]]++; ^ prog.cpp:45:13: error: ‘m’ was not declared in this scope m[v1[i]]++; ^ prog.cpp:47:23: error: ‘m’ was not declared in this scope for ( auto i = m.begin(); i != m.end(); ++i) ^ how to fixed it..
Mr
// { Driver Code Starts // Initial template for C++ #include <bits/stdc++.h> using namespace std; int NumberofElementsInIntersection(int a[], int b[], int n, int o) { // Your code goes here int count = 0; vector<int> v; vector<int> v1; map<int,int> map(map.begin(), map.end()); for(int i = 0 ;i<n;i++){ map[a[i]]++; } for ( auto i = map.begin(); i != map.end(); ++i) { if(i->second >= 1){ v.push_back(i->first); } } // map.clear(); map<int,int> ma(ma.begin(),ma.end()); for(int j = 0 ;j<o;j++){ ma[b[j]]++; } for ( auto j = ma.begin(); j != ma.end(); ++j) { if(j->second >= 1){ v1.push_back(j->first); } } // ma.clear(); map<int,int> m(m.begin(),m.end()); for(int i = 0 ;i<v.size();i++){ m[v[i]]++; } for(int i = 0 ;i<v1.size();i++){ m[v1[i]]++; } for ( auto i = m.begin(); i != m.end(); ++i) { if(i->second > 1){ count++; } } if(count==0){ return 0; } else{ return count; } } // { Driver Code Starts. int main() { int t; cin >> t; while (t--) { int n, o; cin >> n >> o; int a[n], b[o]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < o; i++) cin >> b[i]; cout <<NumberofElementsInIntersection(a, b, n, o) << endl; } return 0; }
Anonymous
// { Driver Code Starts // Initial template for C++ #include <bits/stdc++.h> using namespace std; int NumberofElementsInIntersection(int a[], int b[], int n, int o) { // Your code goes here int count = 0; vector<int> v; vector<int> v1; map<int,int> map(map.begin(), map.end()); for(int i = 0 ;i<n;i++){ map[a[i]]++; } for ( auto i = map.begin(); i != map.end(); ++i) { if(i->second >= 1){ v.push_back(i->first); } } // map.clear(); map<int,int> ma(ma.begin(),ma.end()); for(int j = 0 ;j<o;j++){ ma[b[j]]++; } for ( auto j = ma.begin(); j != ma.end(); ++j) { if(j->second >= 1){ v1.push_back(j->first); } } // ma.clear(); map<int,int> m(m.begin(),m.end()); for(int i = 0 ;i<v.size();i++){ m[v[i]]++; } for(int i = 0 ;i<v1.size();i++){ m[v1[i]]++; } for ( auto i = m.begin(); i != m.end(); ++i) { if(i->second > 1){ count++; } } if(count==0){ return 0; } else{ return count; } } // { Driver Code Starts. int main() { int t; cin >> t; while (t--) { int n, o; cin >> n >> o; int a[n], b[o]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < o; i++) cin >> b[i]; cout <<NumberofElementsInIntersection(a, b, n, o) << endl; } return 0; }
map<int,int> map(map.begin(),map end()) First map refers to a std::map in this code. You are now defining a variable called map in this block which hides the std::map type. Second, you are using map.begin() and map.end() iterators to initialise a map which is just being defined. This is meaningless. You use this constructor only when you are trying to initialise a map from another map or a container of key value pairs.
VENUJAN
a number has 4 bytes but a char has 1 byte how?
VENUJAN
#include <stdio.h> int main(){ int mark[] = {12,34,56,23,21}; mark[0]=3; printf("%d",size); return 0; }
VENUJAN
and why i got 12 here?#include <stdio.h> int main(){ char mark[] = "hello world"; int size = sizeof mark; printf("%d",size); return 0; }
Markiyan
Hi,everyone, I want to calculate this expression 2cos(y) + √sin^3(x) + log4 (sin(y) / (x^4 - y^4)) with these variables(x=0.894, y=13.464). #include <stdio.h> #include <math.h> void main(void) { double x, y, z; printf(“Enter variable x:”); scanf(“%lf”, &x ); printf(“Enter variable y:”); scanf(“%lf”, &y ); z=2*cos(y)+sqrt(pow(sin(x),3))+log(sin(y)/(pow(x,4)-pow(y,4)))/log(4.0); printf(“Result: %lf ”, z); } I wrote this code, it compiles without errors, but when it comes to printing the result. It gives such output. $ gcc test.c -lm $ ./a.out Enter variable x:0.894 Enter variable y:13.464 Result: -nan What does this "-nan" mean? My question is, is this a problem in given numbers or in my code?
olli
So the problem is not in my code, but in the numbers?
yes, with your input tht part sin(y)/(pow(x,4)-pow(y,4)) is negative. If you reverse the input it prints: Result: -5.737740
Markiyan
looks good!
Thanks a lot, that was my main question. Strange thing with these numbers))
VENUJAN
#include <stdio.h> int main(){ char inputData; printf("Enter your string :"); scanf("%c",&inputData); char str[] = inputData; printf("%c",str[]); }
VENUJAN
whats wrong
Melbourne Channel
how do i get my c program to use multicore automatically? is this possible?
GIDDY
How can I write a program to give me an output in descending order
VENUJAN
#include <stdio.h> int main(){ int i,size; char data[] = "ABCA123"; size = sizeof data; for (i= 0;i<size-1;i++){ int box = data[i]; printf("%d\n",box); if ((65 <= box <= 90)) { printf("Alphabets\n"); } } }
VENUJAN
why its working for box values 49,50,51 ??
Pritam
I m facing an error of No newline at end of file
Captain
Implement like this
Captain
#include <stdio.h> int main(){ int i,size; char data[] = "ABCA123"; size = sizeof data; for (i= 0;i<size-1;i++){ int box = data[i]; printf("%d\n",box); if ((65 <= box && box <= 90)) { printf("Alphabets\n"); } } }
Anonymous
How to solve it
Two ways to solve it. 1. Upgrade your compiler or choose a more standard compliant compiler 2. Enter a new line manually at the end of each header file
Anonymous
Thank you so much
Dhiraj
This message couldn't be displayed on your device due to copyright infringement.
ユセフ
Hi
Pavel
Use a condition variable They are meant just for this.
But for condition_variable I will need to also use a mutex and a bool, right? In case that notify was called on the the condition variable by the producer thread before I started checking for it? It feels like a bit of overhead (both more complex code and more work being done).
Anonymous
But for condition_variable I will need to also use a mutex and a bool, right? In case that notify was called on the the condition variable by the producer thread before I started checking for it? It feels like a bit of overhead (both more complex code and more work being done).
Your proposed solution is what is inefficient because there you are doing a busy wait which hogs up the CPU for no reason. In the case where you use condition variables the consumer thread will be blocked (not hogging the CPU) till the producer thread notifies it. This is the more efficient solution and your use case is just one of the simplest use cases for condition variables. Pick any beginner multithreading book and the first example on condition variables will be your use case.
Pavel
I guess I'm asking some not really correct questions, but I just want to understand what I'm doing to make better decisions by myself in future :)
Anonymous
What if I do yeld in the busy loop? Will it still be less efficient in this case? I mean do condition variables send some signal to wake up the thread to be more effective than a loop?
If you yield, then it is just a notification to the OS to schedule other threads. But it also means that there is no guarantee that your thread will be scheduled later when the condition you are checking is satisfied. It could be a while before your thread is woken up if there are other threads also runing. With condition variables the standard doesnt guarantee immediate wake up either but it uses the wording "propagate in reasonable time" which in most cases would be before the yield scenario. Also in the case of yield there could be wakeups before the condition is satisifed which would lead to unnecessary hogging of the CPU again only to yield again.
Anonymous
What if I do yeld in the busy loop? Will it still be less efficient in this case? I mean do condition variables send some signal to wake up the thread to be more effective than a loop?
And yes condition variables do use a signaling mechanism (the one provided by the OS) to notify the OS that the threads waiting on the condition variable need to be woken up. The threads waiting on the cv will be moved to what is known as RUNNABLE state in most standard OS textbooks. They will be available to be scheduled next.
olli
What if I do yeld in the busy loop? Will it still be less efficient in this case? I mean do condition variables send some signal to wake up the thread to be more effective than a loop?
"it depends" how long the other task will run and whether spinning or transitioning into the blocked state is more expensive. For example several lock implementations spin for a couple hundred cycles e.g. using the _mm_pause intrinsic in case it can be acquired early and "block" on it (basically condition variable) after to prevent spending unnecessary time on the cpu.
Anonymous
Who can help me with app I can use to learn programming frre
Gagakputih
Who can help me with app I can use to learn programming frre
You can use online platform to code if you dont want to install any software
Varshan
Send me the platform links please
Just type in google, like c++ online compiler, or any programming language of your choice.
Varshan
https://www.programiz.com/cpp-programming/online-compiler/
Anonymous
Thanks again
Disha
i have a problem with my code
Disha
i need help bz i dont understand whats the problem
Disha
#include<stdio.h> int main() { int n,arr[50],c=0,d=0; printf("Enter the input number:"); scanf("%d",&n); printf("Enter the elements of array:"); for(int i=0;i<n;i++) { scanf("%d",&arr[i]); } int max = arr[0]; for(int i=1;i<n;i++) { if(max<arr[i]) c++; if(arr[0]=arr[i]) d++; } printf("%d numbers are greater than the first element",c); printf("\n%d numbers of that array is similar than the first element",d); return 0; }
Disha
plz tell me whats the problem
__.whizz.__
i want to learn c programming
Ni
Could somebody answer the question:
Ni
ostream * old_tie = cin.tie(nullptr) Seems it returns the cout.
Ni
Is it correct that the tie() returns the former tied ostream?
Ni
I thought it would return nullptr
Ni
The cppreference says the tie() "returns the tied stream, or a null pointer if there was no tied stream". I think it would returns nullptr since cin has no tied stream now
Count
Guys, I have a doubt. I have a variable "name" and is under string. cin>>name will only allow me to take just one name. I want it to take whatever I type. For example, like Jon Doe. Can someone help?
Count
I tried using getline and gets function but it didn't work
_dvd
Hi everyone Quick question: is it possible to use std::copy_n with an input and output iterator belonging to the same fstream opened in both read and write mode? I've tried to do such a thing with a stringstream to implement a sliding window over a text file and it worked, but the same doesn't hold using fstream