Jr. RYAN
Hey guys i am new
I want to learn C++
From where should i start?
Anonymous
Jr. RYAN
Thnx
Anonymous
🆗
Rajul
void sort_by_area(triangle* tr, int n) {
int p=0,i,j,sorted[n][2],temp[1][2];
for(i=0;i<n;i++){
p = (tr[i].a+tr[i].b+tr[i].c)/2;
sorted[i][0] = sqrt(p*(p-tr[i].a)*(p-tr[i].b)*(p-tr[i].c));
sorted[i][1] = i;
}
for(i=0;i<n-1;i++){
for(j=0;j<n-i-1;j++){
if(sorted[j][0]>sorted[j+1][0]){
temp[0][0] = sorted[j][0];
temp[0][1] = sorted[j][1];
sorted[j][0]= sorted[j+1][0];
sorted[j][1]= sorted[j+1][1];
sorted[j+1][0]= temp[0][0];
sorted[j+1][1] =temp[0][1];
}
}
}
for(i=n;i>=0;i--){
printf("%d %d %d\n",tr[sorted[i][1]].a,tr[sorted[i][1]].b,tr[sorted[i][1]].c);
}
}
Rajul
hey guys this is hacker rank problem. i proposed the solution any one tell me where is was wrong
Rajul
YK Y
Rajul
https://www.hackerrank.com/challenges/small-triangles-large-triangles/problem
Mat
Rajul
yes
YK Y
YK Y
And acc to sum sort them and print
Rajul
but in the given problem they have said that i have to sort the array according to the triangle area
Rajul
okk
Anonymous
void sort_by_area(triangle* tr, int n) {
int p=0,i,j,sorted[n][2],temp[1][2];
for(i=0;i<n;i++){
p = (tr[i].a+tr[i].b+tr[i].c)/2;
sorted[i][0] = sqrt(p*(p-tr[i].a)*(p-tr[i].b)*(p-tr[i].c));
sorted[i][1] = i;
}
for(i=0;i<n-1;i++){
for(j=0;j<n-i-1;j++){
if(sorted[j][0]>sorted[j+1][0]){
temp[0][0] = sorted[j][0];
temp[0][1] = sorted[j][1];
sorted[j][0]= sorted[j+1][0];
sorted[j][1]= sorted[j+1][1];
sorted[j+1][0]= temp[0][0];
sorted[j+1][1] =temp[0][1];
}
}
}
for(i=n;i>=0;i--){
printf("%d %d %d\n",tr[sorted[i][1]].a,tr[sorted[i][1]].b,tr[sorted[i][1]].c);
}
}
if you want to use exact formula, you should use floating point calculations, but you used integers!
if you want to calculate everything in integers, you shouldn't use sqrt, or division by 2
Ajay
decltype((i)) d;
why does this decltype returns a reference and not a simple datatype?
Ajay
Ajay
Artöm
int x = 1;
(x) = 2;
Try it, should work
Artöm
It was just slightly surprising example. Usually you have like decltype(a.b()) which can yield T& or T&&
Artöm
Sorry. It can yield T, T& or T&&
Artöm
Yes https://en.cppreference.com/w/cpp/language/decltype
Ajay
Another question,
typedef char *pstring;
const pstring *ps;
Why is ps a double pointer here ? I thought of just replace pstring as char * in the second line of code.
Artöm
ps is pointer to const pointer to non-const char
Artöm
No idea what for. It depends on usage
Artöm
/report
Sweety
/report
Artöm
Abhishek
Hey guys I am beginner in c++
Abhishek
I came around this ques
Abhishek
Consider int val=0xFACE; Write expressions using bitwise operators that do the following:
A. test if atleast three of the last four bits (LSB) are on
B. reverse the byte order (i.e., produce val=0xCEFA)
C. rotate four bits (i.e., produce val=0xEFAC)
Abhishek
Can someone help me? ( If yes then pls pm me)
Francisco
What have you done so far?
Abhishek
Actually I am in first year
Abhishek
So I found this in my assignment
Abhishek
I have done till arrays
lit
Hi
lit
Hi
lit
IAM a human
Abhishek
Francisco
If someone can help it will be appreciated
If you're not willing to try it yourself, don't expect someone to do it for you. Just give it a try and come back later showing what you've done so far
Francisco
We're here to help with specific problems, not to do somebody else's assignment
Abhishek
Sorry for my actions
Welcome
Hi IAM fresher in c language any body help me c learning
MilkBeforeCereal
MilkBeforeCereal
that's all you need
Welcome
Tq
Dima
No
Dima
/warn read the rules
MilkBeforeCereal
useless
MilkBeforeCereal
you won't learn anything from just reading
MilkBeforeCereal
you have to write your own code
Anonymous
http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1256.pdf
Adkhambek
/warn
Preya
Hello! I'm a beginner to c++. I do have some issues I'm facing with undefined reference to 'method' in the istream operator however I already included my .h files. If there's is anyone who is able to help would be great. I have tried to Google but nothing helps to resolve it. Would really appreciate your help.
Sasuke
Preya
Appreciate if you could provide some assistance. Thank you.
Nameful
Nameful
the parenthesis here looks suspicious
Preya
Codeblocks.
NXiss7
Anonymous
Have anyone write one mini kernel OS in C++ + Asembler for Intel 8086 Architecture in BCC compiler for huge memory model? That is project that i have to do in this semester, so if anyone could be of help can pm me. It is nice experience for someone who has experience in C++ to help me 😊 Cheers 🥂
ZukiZest
anyone can explain?
ZukiZest
ZukiZest
strtol idk
Artöm
Find strtol on cppreference.com
maq
Somebody pls help me write a c++ program that calculates and reports the errors
Dima
no
maq
NXiss7
ZukiZest