answersLogoWhite

0

For example:

c = a + b;

(This calculates the sum of a + b, and assigns the result to variable c.)

If you repeatedly want to add something to an accumulated sum:

b = b + a;

or better:

b += a;

For example:

c = a + b;

(This calculates the sum of a + b, and assigns the result to variable c.)

If you repeatedly want to add something to an accumulated sum:

b = b + a;

or better:

b += a;

For example:

c = a + b;

(This calculates the sum of a + b, and assigns the result to variable c.)

If you repeatedly want to add something to an accumulated sum:

b = b + a;

or better:

b += a;

For example:

c = a + b;

(This calculates the sum of a + b, and assigns the result to variable c.)

If you repeatedly want to add something to an accumulated sum:

b = b + a;

or better:

b += a;

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
ReneRene
Change my mind. I dare you.
Chat with Rene
LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao
More answers

Use the addition operator (+). The operands need not be of the same type (mixed-mode arithmetic) but one or both operands will be implicitly cast to the appropriate type to suit the expression.

void f (int i, double d) {

double x = i + d; // implicitly cast i to double

int y = i + d; // implicitly cast d to int

}

User Avatar

Wiki User

8y ago
User Avatar

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,sum;

printf("Enter two nos.");

scanf("%d%d",&a,&b);

sum=a+b;

printf("Sum is = %d",sum);

getch();

}

User Avatar

Wiki User

14y ago
User Avatar

Arrays in programming languages can seem daunting at first. But, once the basic principles behind them are grasped, one can write and use them with a minimal of thought or concern.

An array is just a list of items progressing from start to finish. Each item (element) in an array consists of a value. In C, each value in an array must have the same type. So, an array is a list of signed integers (int), or a list of unsigned characters (unsigned char), or a list of character arrays (char*), or a list of elements of any single type (including structs). The first three examples are declared as follows (assuming 10 elements per list):

int intlist[10];

unsigned char ucharlist[10];

char *chararrlist[10];

Assuming that you wish to calculate the sum of the elements in an array of signed integers (int), you would first declare the array as above, use a loop to or other algorithm to populate it with values, and then use a loop to add the values together. Here's an example of looping through an array to set each element value to the loop counter:

int count;

for (count=0; count<10; count++) intlist[count]=count;

This results in intlist[] containing the values: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

Next, you will want to declare a tally variable. Because the values are small, you can simply use a type of "int":

int tally=0;

This is initialized to a value of "0" before you proceed through the list.

The final task is to use the same loop statement as above, but, instead of setting each element value in the array, adding the value of each element to the variable "tally":

for (count=0; count<10; count++) tally+=intlist[count];

The "+=" operator tells C that you want to add the value at intlist[count] to the value of "tally", and then store that result in "tally".

Finally, you can display the result:

printf("The values of all elements in the list add up to %d.\n", tally);

And that's it! You can use array loops to display array list values, write values to files, and much more.

See the related link below for further details on C arrays.

User Avatar

Wiki User

12y ago
User Avatar

For example:

c = a + b;

(This calculates the sum of a + b, and assigns the result to variable c.)

If you repeatedly want to add something to an accumulated sum:

b = b + a;

or better:

b += a;

User Avatar

Wiki User

15y ago
User Avatar

You add numbers as follows:

sum = a + b;

User Avatar

Wiki User

14y ago
User Avatar

The sum of every odd number is infinite.

User Avatar

Wiki User

16y ago
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write c program to find sum of two numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp