int sum = 0; int i; for(i = 0; i < n; ++i) { sum += i; }
Sum = n/2[2Xa1+(n-1)d] where n is last number, a1 is the first number & d is the common difference between the numbers, here d=2 for the even /odd numbers. Sum = n/2 [2Xa1+(n-1)2]
to print the sum of first ten numbers:- void main() {int i,sum; sum=0; while(i<=10) sum=sum+i; i=i+1; } printf("The sum is : %d",sum); }
#include #define NUM 100 //since prog is to be written for adding 100 naturalint main(){int i,sum=0;for(i=1;i
Oh, what a lovely question! To compute the sum of the squares of N numbers, you can create a simple algorithm. Start by initializing a variable to hold the sum, then loop through each number, square it, and add it to the sum. Once you've done this for all N numbers, you'll have the sum of their squares. Just like painting a happy little tree, take your time and enjoy the process.
To get a list of the squares of the first 1000 numbers we can do:> [n^2 | n sum [n^2 | n
The sum of the first n cubed numbers is: [n*(n+1)/2]2 which is the same as the square of the sum of the first n numbers.
The average of n numbers = (sum of n numbers) / (count of n numbers).
main() { int i, n, sum=0; cout<<"Enter the limit"; cin>>n; for(i=0;i<=n;i++) sum=sum+i; cout<<"sum of "<<n<<" natural numbers ="<<sum; getch(); }
It depends on the script language you are using. In the Korn shell, you can say: echo -n "Enter the first number: " read first echo -n "Enter the second number: " read second let third=$first+$second echo The answer is $third
try a for loop: for x in 1 2 3 4 n=0 do n=`echo $x+$n`|bc done Integer arithmetic can be done in the shell itself without requiring an external program, making the operation much faster: n1=123 n2=543 sum=$(( $n1 + $n2 )) echo "$sum"
Mean = (sum of the n numbers)/n
The sum of the first "n" numbers is equal to n(n+1)/2.
i need 2 numbers whose sum is 832AnswerThe numbers are n and (832 - n) where n is any number from 0 to 416.
There is no formula that will sum n even numbers without further qualifications: for example, n even numbers in a sequence.
SUM = 0: FOR N = 1 to 100: SUM = SUM + N: Next N: PRINT CHR$(11); "Sum ="; SUM: END
int sum = 0; int i; for(i = 0; i < n; ++i) { sum += i; }