Xra a [(making the accumulator zero) or you can also write
mvi a,00 but will probably take more t-states]
lxi h dooo(can be any other address)give the range(n)
mov b,m
mvi c,01
again: add c
inr c
dcr b
jnz again [loop]
inx h
mov m,a
hlt
int sum = 0; int i; for(i = 0; i < n; ++i) { sum += i; }
#include #define NUM 100 //since prog is to be written for adding 100 naturalint main(){int i,sum=0;for(i=1;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]
huh?
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); }
sample program in sum of the series using the formula for s=n/2[2a+{n-1}d] in 8085
int sum(n) { if (n==0) return 0; else return n+sum(n-1); }
write an assembly language program to find sum of N numbers
#include<stdio.h> void main() { long long int sum=0,n,i,b; printf("How many numbers do you want to add?\n"); scanf("%lld",&n); printf("Enter those %lld numbers\n",n); for(i=0;i<n;i++) { scanf("%lld",&b); sum=sum+b; } printf("Sum of all the numbers you entered is %lld",sum); getch(); }
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).
The sum of the first ( n ) even numbers can be calculated using the formula ( S = n(n + 1) ). This is derived from the fact that the ( n )-th even number is ( 2n ), and the sum of the first ( n ) even numbers is ( 2 + 4 + 6 + \ldots + 2n ). By factoring out 2, the sum simplifies to ( 2(1 + 2 + 3 + \ldots + n) ), which is ( 2 \times \frac{n(n + 1)}{2} = n(n + 1) ).
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(); }
for (n=1; n<1000; ++n) { for (sum=0, k=1; k<=n/2; ++k) if (n%k==0) sum += k; if (sum==n) printf ("%d\n", n); }
The sum of the numbers from 1 to 60 can be calculated using the formula for the sum of an arithmetic series: ( S_n = \frac{n(n + 1)}{2} ), where ( n ) is the last number in the series. For the numbers 1 to 60, ( n = 60 ). Thus, the sum is ( S_{60} = \frac{60(60 + 1)}{2} = \frac{60 \times 61}{2} = 1830 ). Therefore, the sum of the numbers from 1 to 60 is 1830.
Sum of numbers in a nth row can be determined using the formula 2^n. For the 100th row, the sum of numbers is found to be 2^100=1.2676506x10^30.
Mean = (sum of the n numbers)/n