1
I need a way that the program performs an account between variables x
and y
and save the result in a variable z
, how do I do it in C?
1
I need a way that the program performs an account between variables x
and y
and save the result in a variable z
, how do I do it in C?
4
Would this be:
#include <stdio.h>
int main() {
int x, y;
printf("Entre com 2 números: ");
scanf("%i %i", &x, &y);
int z = x + y;
printf("\n%i", z);
}
Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.
This line printf("%i",z, y+x==z);
is the biggest confusion. This is adding up the two variables and comparing with z
, is not assigning to the variable as requested. And is sending 2 arguments for formatting the printf()
.
Also the variables were not initialized and eventually can bring problems. Still the lack of organization makes it difficult to read the code. Organizing makes it easier to understand what is happening.
Browser other questions tagged c variables
You are not signed in. Login or sign up in order to post.
You have to try something and post the code detailing where the difficulty is.
– rubStackOverflow
What account should you make?
– Maniero
addition between variable x and variable y, resulting in variable z
– Strule
Write a function that performs the account and return the result:
z = conta(x, y);
– pmg
@Strule Did the answer solve your problem? Do you think you can accept it? If you don’t know how to do it, check out [tour]. This would help a lot to indicate that the solution was useful to you and to give an indication that there was a satisfactory solution. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero