answersLogoWhite

0


Best Answer

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

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

7y ago

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

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

#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();

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

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.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

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;

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

You add numbers as follows:

sum = a + b;

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

The sum of every odd number is infinite.

This answer is:
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
Related questions

How do you write an assembly language program to find the sum of n numbers using array?

write an assembly language program to find sum of N numbers


Write a C program to find the sum of all prime numbers?

Since there is an infinite set of prime numbers the answer would be infinity.


How do you find sum of 100 numbers using fortran programme?

The following is for F95 and later (due to the use of intrinsic SUM ): My assumptions: -Your numbers are integers -Your numbers are stored in an array -The numbers you are describing are 0-100 program findSum !I assumed integer, replace this with your data type integer, dimension(100) :: numbers integer :: sumOfNumbers !We populate an array with our numbers !Replace this with your numbers do i=1,(size(numbers)+1) numbers = i end do !We find the sum of those numbers sumOfNumbers = sum(numbers) !We write out the sum to prompt write(*,*) 'Sum is: ', sumOfNumbers end program findSum


How. to. write an. algorthim. to find the. sum of. first. 15 natural. numbers?

Write an. Algorthim. To. Find the. Sum. Of. First15 natural. Numbers


Write a program to find the sum of even numbers from 2 to50?

In Java:sum = 0;for (i = 2; i


Write a java program to find sum of even and odd numbers in given array?

for(int i = 1; i &lt; 100; i+=2) { System.out.println(i); }


Write a C Program to print sum of squares of odd numbers?

#include


Write a C program to find sum of 3 matrices?

matrix


Write a c program to find the sum of numbers between given limits?

int sum (int min, int max) {return (max-min+1)*(max+min)/2;}


Java program to find sum on even numbers from 12-45?

sum = 0; for (int i = 12; i


Write a program that read 10 numbers from the user and display their sum?

#include&lt;stdio.h&gt; void main() { int num, sum=0, i; printf("Enter ten numbers: \n"); for(i=0;i&lt;10;i++) { scanf("%d",&amp;num); sum += num; } printf("\n The sum of the numbers is %d",sum); getchar(); }


Write c sharp program to find sum of two numbers?

public int findSum(int n1, int n2) { return n1 + n2; }