#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.
@@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
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++.
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; }
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;
}
Very help . For you thank you
How can I get 30s of my life back. Do it using pointers.
Very helpful.. thank you so much 🙏
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.
Fun to code
Use correct initialization int a{}, etc.
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
I was always doing cout no. 1;
And then repeat with no. 2 but i see that i can just do cin >> a >> b;
Very easy
Thanks
Me it has failed
This music is a W
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.
❤
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.
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
in cout, remove the quotes where a+b so the numbers that you entered instead of letters will be output
But you can make it with "switch" and "case" or also "if" and "else"
Isnt that Python?
Where is the enter button in the phone
c++ k program kha pr bnte h
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
bro 1 error is generating
what error
Syntax error
Konsi app hai bhai
what about the random sum?
Что такое return и надо ли это убрать?
Taking a look at c++ and im already getting brainf###
twenny one
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
Bro substraction
can you make a video about x, and y
Yes we can by using pointers 👌🏻
What name of the app
C++ bruh 😎😂😂😂😅😅
💀
👍
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.
What apps do u use?
Dont knowi
Ok
Hi
what program is this
c++
How the battery Percentage increases while the program is runned 😂
11
very hard algorithm
its the easiest one
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
Ye kon sa app h bhai ?
C++ coding❤
@@baisahmad3343 thanks 👍
vs code hi micro soft ka free
Replit use karo
Online c++ compile
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.
Wrong this code 😢
Error
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;
}
Fun to code