Viprr
Book
@𝑺𝒐𝒃𝒌𝒂
Yasas
Can somebody help me?
I wrote a c++ program which was like a calculator.
I compiled it and it worked fine on my laptop.
But when I try to execute it on another computer it doesn't work.
Why does this happen?
Pavel
dipesh
hey
dipesh
myPow(double x, int n) while making this power user defined function how can i get result for negative power coefficient
dipesh
double myPow(double x, int n){
int i;
float ans=1;
if(n==0)
{
return 1;
}
else
{
for(i=1;i<=n;i++)
{
ans=(float)ans*x;
}
return ans;
}
}
Anonymous
dipesh
great . thanks a lot
Anonymous
Btw ans should be a double variable and get rid of the casts to float
dipesh
Anonymous
dipesh
for 2 to the power -2 im still getting 1 instead of 0.25
dipesh
#include<stdio.h>
double myPow(double x, int n);
int main()
{
float x,ans;
int n;
scanf("%f",&x);
scanf("%d",&n);
ans=myPow( x, n);
printf("%f",ans);
}
double myPow(double x, int n){
int i;
float ans=1;
if(n==0)
{
return 1;
}
else
{
for(i=1;i<=n;i++)
{
ans=(float)ans*x;
}
return (n>0)?ans:(1/ans);
}
}
Anonymous
dipesh
what does that abs(n) means
Anonymous
what does that abs(n) means
https://en.cppreference.com/w/cpp/numeric/math/abs
Ignore the std:: namespace stuff. The function meaning is otherwise same in both C and C++
dipesh
i didnt got it i am just learning c and dont know much abbout c++\
Anonymous
return (n>0)?ans:(1/ans);
use float(1/ans)
ninja
abs(n) == |n|
dipesh
Anonymous
Anonymous
got it
🅸🅼🆁🅰🅽
C is legendary
Ravi
1 3 4 5 9
Anonymous
Anonymous
Cant you do it yourself or try it on your own system? What is the point of questions like this?
tumaini
C++ line to limiti, the number of digits for a number to be entered by a user
Help, please🙏
255mufasa
which stuffs are you guys using in studying c++
255mufasa
i dont understand it cleary
255mufasa
255mufasa
i just see stars😞
Anonymous
/get cbook
255mufasa
thank you👍
NAM3L3SS
#include <iostream>
Using namespace std;
int main()
{
String name;
Cout<<"Enter the name:"<<endl;
Cin>>name;
While(name<5)
{
Cout<<name;
name++;
}
return 0;
}
NAM3L3SS
Hey fam am trying to loop a name from the user 4times
NAM3L3SS
Any help
Ravi
take a variable other than name which will be int to store the count of loops
tumaini
#include<iostream>
Using namespace std;
Int main()
{
int salary;int number;
Salary=1000000;
Court<<"Enter your credit card number" \n;
Cin>>number;
If(condition)
{
Cout<<" Your net salary is "<<salary<<endl;
Cout<<"After VAT deduction your base salary is"<<salary*0.2<<endl;
}
else
Cout<<" your credit card number is wrong";
return 0;
}
//Please help me with the condition that can limit number to have any 13 digits using if condition//
NAM3L3SS
Anonymous
Hello
Anonymous
Hello please who can help me to write a code c for humanoide robot with arduino 😔🙏🙏
Talula
Anonymous
I want to move as much as possible and even walk
Anonymous
Hello brother can anyone say my codebits correct or not ❓
•‿•
#include <stdio.h>
int main()
{
int a, b;
b = -3 --(-3);
printf("b =%d ", b);
return 0;
}
•‿•
why this show error
Ravi
•‿•
where?
Ravi
-3-(-(-3))
Ravi
like this
JY
-3 -4 missing operator
JY
Two numbers
JY
-3 - --(-3) will work
Anonymous
Anonymous
why this show error
It shows an error because the pre decrement operator requires an lvalue but -3 is a rvalue
•‿•
here is - - - subtraction sign
•‿•
•‿•
oh understand
•‿•
hey can you suggest me where to practice c programming question
•‿•
i want to practice
JY
Compiler should figure it out. From user perspective, what is difference? It should use a temp var for -3. User intention is clear
JY
Does (-3)-- work?
JY
Does (-3)-- work in python for example
Anonymous
Anonymous
Does (-3)-- work?
The post decrement also requires an lvalue. The difference with predecrement is that predecrement returns an lvalue while post decrement returns an rvalue.
Hanz
Because you havent assign anything to comp
Pavel
comp == is not assignment, should be one =
Hanz
Change all == to = in your first three if nodes in main