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; }
1. Design an algorithm to compute sum of the squares of n numbers?
#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?
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).
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); }
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(); }
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
The sum of the first "n" numbers is equal to n(n+1)/2.
There is no formula that will sum n even numbers without further qualifications: for example, n even numbers in a sequence.