#include int main(void) { Int x, y, sum; printf(“Enter two numbers: ); scanf(“%d%d”, &x, &y); sum = x+y; printf(sum); Or, forgo sum altogether and printf(x + y); return 0; }
What about if you want the user to be able to enter more numbers for the sum without knowing how many numbers he will enter? Asking because that’s my homework for this week. Trying to figure out how to write a program for multiple numbers where as it outputs sum of even numbers, sum for odd numbers, and total sum.
Use the "for" loop. int n, x, s=0; cin >> n; for(int i=1; i> x; // this will be read n times s = s + x; // adds the current number to the sum } Let's say you have 4 numbers (3 7 9 18). i (from the for loop) will start out as 1, it will check if it's smaller then n (which in this case will be 4, cause we have 4 numbers) then it will execute what's inside the for loop. Then i will increase and so on. I'm guessing you know how to check if a number is odd or even using if statements.
Add a do while loop so that until the user enters a sentinel value, they will continuously add numbers. Here's a way of doing that in English/code terms. int number; int sum = 0; do{ cout > number; sum += number; }while(number != -1) cout
Slight correction because u reversed int and input and forgot quotation marks: a = int(input("Enter the first number: ")) b = int(input("Enter the second number: ")) print(f"The sum of {a} and {b} is: {a + b}") or print(f"The sum of {a} and {b} is: ", a + b
@@Merovingien514It doesn't require memory? The reason it's considered bad practice is because you're likely to get naming collision between functions. That's why they made std namespace.
I don’t think “using namespace std” is a healthy convention. In a larger codebase, you might accidentally overwrite one of the std functions if someone unknowingly writes a function with the same function name as a common std function
In C this program looks like this: #include int main() { int a, b, sum; printf("Enter two numbers: "); scanf("%d%d", &a, &b); sum = a + b; printf("a + b = %d", sum); return 0; }
Using namespace std, declaring all your variables at the top of a scope block, and using a comma to declare multiple things on one line are all horrible practices in C++.
C :
#include
int main() {
int x = 5;
int y = 6;
int sum = x + y;
printf("%d, sum);
return 0;
}
Output : 11
#include
int main(void) {
Int x, y, sum;
printf(“Enter two numbers: );
scanf(“%d%d”, &x, &y);
sum = x+y;
printf(sum);
Or, forgo sum altogether and
printf(x + y);
return 0;
}
Bro ur contact number please some doubts
@@drfutato🎉🎉❤❤
#include
Int main()
{
Int a, b, c
C=a+b;
Cout>b;
}
What’s that
How can I get 30s of my life back. Do it using pointers.
Y bhtt intrsting h yrr m to ab shuru krri hu seekhna i am b com krliya h ab complete but man h to bs seekhna h ye bhi i hope easy rho
all the best! it's always good to see a non-techy trying coding
You should use
export inline template requires (Ty1 obj1, Ty2 obj2) { obj1 + obj2; } auto get_sum(const Ty1& obj1, const Ty2& obj2)->decltype(obj1 + obj2)noexcept(noexcept(obj1 + obj2)){
return obj1 + obj2;
}
Not really.
Try hard
True
or just use double datatype
Why? If he wants to add two integers, then he will add two integers, no need for templates. Don't complicate things.
Very helpful.. thank you so much 🙏
Very help . For you thank you
Thanks, it works.
What about if you want the user to be able to enter more numbers for the sum without knowing how many numbers he will enter? Asking because that’s my homework for this week. Trying to figure out how to write a program for multiple numbers where as it outputs sum of even numbers, sum for odd numbers, and total sum.
Use the "for" loop.
int n, x, s=0;
cin >> n;
for(int i=1; i> x; // this will be read n times
s = s + x; // adds the current number to the sum
}
Let's say you have 4 numbers (3 7 9 18). i (from the for loop) will start out as 1, it will check if it's smaller then n (which in this case will be 4, cause we have 4 numbers) then it will execute what's inside the for loop. Then i will increase and so on.
I'm guessing you know how to check if a number is odd or even using if statements.
Add a do while loop so that until the user enters a sentinel value, they will continuously add numbers.
Here's a way of doing that in English/code terms.
int number;
int sum = 0;
do{
cout > number;
sum += number;
}while(number != -1)
cout
@@TheSpacePlaceYTUhh... You didn't put a limit or any context why they need to put -1. Your code literally never stops otherwise.
in cout, remove the quotes where a+b so the numbers that you entered instead of letters will be output
Right TNX
I was always doing cout no. 1;
And then repeat with no. 2 but i see that i can just do cin >> a >> b;
meanwhile in python
a=input(int(enter first num))
b=input(int(enter second num))
print(f"sum of {a} and {b} is", a+b )
amd thats all
Less readable
Slight correction because u reversed int and input and forgot quotation marks:
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
print(f"The sum of {a} and {b} is: {a + b}")
or
print(f"The sum of {a} and {b} is: ", a + b
@@Bird53826 used f string, and then put the a + b outside, what's the point?
@@Wutheheooooo because without the f string {a} and {b} wouldn't work
Very easy
Python
a=input(int(enter first number))
b=input(int(enter second number))
Print(f"sum of {a} and sum of {b} is" ,a+b)
Fun to code
Sup fellow coder that uses android to code 👊😊😊
Bro wats up
I need some help
@@kahumaisaac7699why bro? Do you have any troubles in your code?
what u need help with
@@kahumaisaac7699
I would genuinely rather walk on burning coal than code on mobile, no offense
Me it has failed
Use correct initialization int a{}, etc.
?
@@RetroFlexXx it's direct list initialization, initialize ur variables
But you can make it with "switch" and "case" or also "if" and "else"
Isnt that Python?
bro 1 error is generating
what error
Syntax error
the horizontal and vertical whitespacing in this code is making me have a conniption
Lol, std::cout instead of using namespace std😅
It's not funny. Both are correct.
@@toby9999 For a beginner programmer, yes, but in real projects, using namespace std can consume memory.
@@Merovingien514consume memory? I don't think so.
@@Merovingien514It doesn't require memory? The reason it's considered bad practice is because you're likely to get naming collision between functions. That's why they made std namespace.
Where is the enter button in the phone
This music is a W
Please 🙏 what is the name of the compiler I are using plz
Thanks
#include
int main(){
int a = 10;
int b = 25;
int c = a+b;
std::cout
Please i want to learn how it works
Most easy program
I don’t think “using namespace std” is a healthy convention. In a larger codebase, you might accidentally overwrite one of the std functions if someone unknowingly writes a function with the same function name as a common std function
Cbhcvbllppghpogvkjgfgoihgoougi0
App name?
It would have been better if you wrote:
cout
Nyc kia programming hwy apki well-done
it would be better to write
cout
@@RaoRawal786 kyun yaar isme galat kya hai? main abhi bhi sikh raha hun class 8 mein hu mein
@@user-zx5xx4qu1h yeah that can be done either
c++ k program kha pr bnte h
Что такое return и надо ли это убрать?
guyz i wanna be ethical hacker what coding language should i learn?
I simply skipped the video because you did not enter a space between the include to the iostream library
what about the random sum?
What name of the app
C++ bruh 😎😂😂😂😅😅
❤
can you make a video about x, and y
Yes we can by using pointers 👌🏻
Taking a look at c++ and im already getting brainf###
purna
No need return 0
App name???
C++ coding
How the battery Percentage increases while the program is runned 😂
Konsi app hai bhai
jse c program turbo c or bnte h usi trha c++ kha bnte h
C++ code b Turbo per run ho jata hai but try Dev C++, it is much better than Turbo.
very hard algorithm
its the easiest one
In C this program looks like this:
#include
int main()
{
int a, b, sum;
printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
sum = a + b;
printf("a + b = %d", sum);
return 0;
}
Instagram program
Bro substraction
Yeueu;
What apps do u use?
Dont knowi
Ok
Ye kon sa app h bhai ?
C++ coding❤
@@baisahmad3343 thanks 👍
vs code hi micro soft ka free
Replit use karo
Online c++ compile
Bro in which app?
C++
@@savitabhople2774app?not
What are u doing here😂😂
No but which version
I want to install but I can't this exact same
what program is this
c++
Using namespace std, declaring all your variables at the top of a scope block, and using a comma to declare multiple things on one line are all horrible practices in C++.
Says who? You?
Why? xD
Using namespace std is fine for such simple programs. Multiple declarations separated by comma is also fine, it's valid syntax.
twenny one
Hi
👍
💀
Wrong this code 😢
11
Error
Fun to code
Please i want to learn how it works
App name?