Anonymous
Is somebody familiar with theoretical computer science like pumping lemma or deterministic finite automata
Not meant for this community. Check out the Theory of Computation tag in Stackoverflow
Shruti Debnath 376 Cse 25
#include<stdio.h> int main() { int i, min,max,size; int arr[size]; printf("enter size of array\n"); scanf("%d", &size); printf("enter elements of the array\n"); for(i=0;i<size;i++); { scanf("%d", &arr[i]); } max=arr[0]; for(i=0;i<size;i++) { if(arr[i]<arr[i+1]) max=arr[i+1]; } printf("the max element is %d\n", max); min=arr[0]; for(i=0;i<size;i++) { if(arr[i]>arr[i+1]) min=arr[i+1]; } printf("the max element is %d", min); return 0; }
Shruti Debnath 376 Cse 25
I cant figure out where im making a mistake in this code
Shruti Debnath 376 Cse 25
It returns garbage value
Golden Age Of
It returns garbage value
And u don't actually need to compare arr[i] and arr[i+1] to find min, u can just compare your min with every arr[i]
Golden Age Of
Shruti Debnath 376 Cse 25
O okk goddit
Shruti Debnath 376 Cse 25
Thanks :)
\Device\NUL
#include<stdio.h> int main() { int i, min,max,size; int arr[size]; printf("enter size of array\n"); scanf("%d", &size); printf("enter elements of the array\n"); for(i=0;i<size;i++); { scanf("%d", &arr[i]); } max=arr[0]; for(i=0;i<size;i++) { if(arr[i]<arr[i+1]) max=arr[i+1]; } printf("the max element is %d\n", max); min=arr[0]; for(i=0;i<size;i++) { if(arr[i]>arr[i+1]) min=arr[i+1]; } printf("the max element is %d", min); return 0; }
size var is undefined before declaring Variable length array, also vla is bad AND USING VLA'S IS ACTIVELY STUPID! It generates much more code, and much _slower_ code (and more fragile code), than just using a fixed key size would have done. - Linus Torvalds Ref: https://lore.kernel.org/lkml/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com/
Alessandro
to allocate an array of size decided by the user, you should use malloc. does your code compile like that?
Alessandro
the size of the array cannot be computed at compile time, i don't think the compiler is smart enough to handle the variable size
Alessandro
it does but the array "arr" is allocated with lenght equal to the content of the variable size, witch is undefined behaviour
Pavel
size var is undefined before declaring Variable length array, also vla is bad AND USING VLA'S IS ACTIVELY STUPID! It generates much more code, and much _slower_ code (and more fragile code), than just using a fixed key size would have done. - Linus Torvalds Ref: https://lore.kernel.org/lkml/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com/
Well, after thinking a bit more about it, I agree Wasting space doesn't matter if we never going to overflow (we know how much of stack we can use), then it's better to use fixed size arrays in this case just because it's faster. If there's possibility of stack overflow because of vla, then it's just bad.
Anonymous
I don't often agree with Torvalds, but I do on that topic
I do agree that VLAs will be slightly slower but the fact that VLAs make typedefs generate executable code was a new path charted out by the C99 Standardization team. Typedefs don't generate executable code for anything except VLAs
Levi
Anyone help me out plz, im in learning period of C..
Where r u learning from like which website
AmR
Can I set qt-creator with mingw in Linux ?
ɛ n h ᴀ n c ɛ ґ 🧟‍♂️
int temp, sizearr; int *elements; cout << "How many Numbers do you want to sort? "; cin>> sizearr; elements = new int[sizearr]; for (int i = 0; i <sizearr; i ++ ){ cout << "Enter Number "<<i+1<< ":"; cin >> elements[i]; } cout<< "{"; for (int i = 0; i < sizearr; i++){ cout<< elements[i] << "," ; } cout<< "}"; cout<< "\n\n"; for (int i =0 ; i < sizearr; i++){ for(int j = 0; j< sizearr - 1; j++){ if(elements[j+1] > elements[j]){ temp = elements[j]; elements[j] = elements[i+1]; elements[i+1] = temp; } } } cout << "{"; for (int i = 0; i < sizearr; i++){ cout<< elements[i] << ","; } cout << "}"<<endl; cout << "\nSecond Largest Number is: "<<elements[1]; return 0;
Ludovic 'Archivist'
Meaning you may randomly take something that is outside of your array every once in a while, which may be your error
Ludovic 'Archivist'
Works now
My advice would be to not use indexes but use iterators instead. This would most likely have made your mistake more visible
Shruti Debnath 376 Cse 25
Can somebody please suggest a good playlist or course to learn OOP in C++?
Shruti Debnath 376 Cse 25
How is the abdul bari c++ course. I noticed it covers almost all basic topics, oop concepts and stl
Shruti Debnath 376 Cse 25
https://www.udemy.com/course/master-cpp-byteboard/
Shruti Debnath 376 Cse 25
If somebody has tried out this udemy course, please let me know how is this course and which one should be preferred more between the above two.
Nameful
> or any other countries why even list them if it applies to literally any country
Saddam
Can anyone guide me how should I learnt Data structure I'm feeling lots of problems in data structures
Nameful
Try implementing one yourself
Rafael
Thanks
Rafael
But on c++ I have no experience
Rafael
Hi, of course you can
Anonymous
Shoot
Bohdan
Hi! Can someone explain me the syntax of int& get() {return x;} function? #include <iostream> using namespace std; class MyClass { int x; public: MyClass(int val) : x(val) {} const int& get() const {return x;} int& get() {return x;} }; int main() { MyClass foo (10); const MyClass bar (20); foo.get() = 15; // ok: get() returns int& // bar.get() = 25; // not valid: get() returns const int& cout << foo.get() << '\n'; cout << bar.get() << '\n'; return 0; } Output: 15 20
Bohdan
i don't get the need of & after int
Bereket
#include <iostream> using namespace std; // newList is the reversal of list void reverse(const int list[], int newList[], int 10) { for (int i = 0, j = 10 - 1; i < 10; i++, j--) { newList[j] = list[i]; } } void printArray(const int list[], int 10) { for (int i = 0; i < 10; i++) cout << list[i] << " "; } int main() { const int SIZE = 10; int list[] = {1, 2, 3, 4, 5, 6,7,8,9}; int newList[10]; reverse(list, newList, 10); cout << "The original array: "; printArray(list, 10); cout << endl; cout << "The reversed array: "; printArray(newList, 10); cout << endl; return 0; }
Jk
Try (-1*b + sqrt(d))/(2*a)
Börke(МБорке)
Hi mates, is there any person who knows Emacs? I would like to add some features using C language
𝗝ลѴỈ3𝚪Θ
Hi, i looking for a test remote port check in a windows application. Anyone know a simple library for that?
Börke(МБорке)
What is it you want to do exactly?
i would like to be able to change contrast brightness of text colors for theme, so for text shade (rendering) as I know lisp can't do that but rather need to add something to C
Azhar
Write a program to read an integer number of any lengths. Perform the addition and subtraction on the largest and smallest digits of it. Your program must satisfy the following conditions: 1) The number should not cross the unsigned short int maximum value. If the entered value did not satisfied the condition asked to input it again till satisfies the condition. 2) To check the number within the range of unsigned short int use the available constants from limits.h header file. 3) Solve this problem using user-defined function.
Azhar
Can anyone help me out
Azhar
Message me so that i can share u image file.. Help me plz bro
Safwan
#include<iostream> using namespace std; int main() { char a='1'; char b='2'; cout<<a+b; // I want the output equal number 3 please can anyone help me?
Anonymous
Hi
Anonymous
I wanna hellp
Anonymous
Code c++ for non prime number and sum the all non number
Anonymous
For between 2 number
Anonymous
Prime number ???
Ludovic 'Archivist'
Code c++ for non prime number and sum the all non number
Proceed step by step, write how you would do it by hand, then try to apply that to your computer
Ludovic 'Archivist'
I dont know 🥲💔
I'd recommend going back to middle school if you cannot even solve your problem on paper. I know it sounds harsh but sadly I don't feel like giving highschool math courses
VladV1V
I dont know 🥲💔
Task you wrote is aviable in google... There is no thing like just do code for me. Try yourself first than ppl here will help to find mistakes. You wont learn anything without doing anything
Anonymous
cout << char(a + b - '0')
Not a great idea but. Why do you even want to code like this?
Anonymous
It's just a homework.
Well your teacher is giving you bad code examples. Looks more like a puzzle exploring facets of C++ that you won't ever use (unless this is an exercise on trying this program using different encoding systems which I doubt it was). Even then, on all the encoding systems that I have used, '0', '1'...,'9' are assigned consecutively.
Anonymous
They solve?
No. Pastebin won't solve your coding problems. It is just a site used to share code. You post your code there and send us the link here. We can check your code and guide you
Roman
Hello, how can i listen to keyboard events globaly, not from the console in C?
Anonymous
Technvi: Koi c++ m master hai Mujhe help chahiye c++k program m koi kr skta hi ????
Roman
that's system dependent
I am using windows, i've red about conio.h, is it the only way to do it?