Q: What is the sum of 0 to 100?

Write your answer...

The following will sum all integers from 1-100. Adjust according to your needs.int sum = 0;for (int i = 1; i

int i, sum; /* example using while */ sum = 0; i = 1; while (i <= 100) { sum += i; ++i; } /* example using for */ sum = 0; for (i = 1; i <= 100; ++i) sum += i;

You add the numbers in a loop. Here is an example in Java:int sum = 0;for (int i = 1; i

75 - 100 + 0 = -25

public class Test { public static void main(string args[]){ int sum = 0; for(int i = 0; i <= 100; i++){ sum = sum + i; } System.out.println("Sum = " + sum); } }

class sum { void main () { int sum = 0; int n = 1; while ( n <= 100 ) { sum = sum + n; n++ ; } System.out.println("Sum is = " + sum ); }}

public class TestBB { /** * @param args */ public static void main(String[] args) { int sum = 0; int i = 0; do { sum = sum + i; i++; } while (i <= 100); System.out.println("Total of 100 numbers is: " + sum); } }

...int sum = 0;for (int i = 101; i

#includeint main(){int i,sum=0;for(i=1;i

#include #include void main() { int sum=0,avg=0,a[100],i=0,j=0,k=0; printf("enter the number of elements wanna add"); scanf("%d",&n); for(j=0;j<n;j++) { k=j+1; printf("Enter rank %d element element ",k); scanf("%d",&a[j]); } //for sum for (i=0;i<100;i++) { sum=a[i]+sum; } printf("sum of nos %d",sum); for (i=0;i<100;i++) { avg=sum/n; } printf("avg of nos",avg); getch(); } //you can change avg from int to float to get in decimals.

SUM = 0: FOR N = 1 to 100: SUM = SUM + N: Next N: PRINT CHR$(11); "Sum ="; SUM: END

// finds this sum in range (1, 100] int sum = 0; for(int i = 2; i < 101; i+=2) { System.out.println("Adding : " + i); sum += i; } System.out.println("Sum : " + sum);

its 5035the summarian notation tells you that(sum of all #from 0 to a number'N'(sum of all #from 0 to N) = (n)+(n-1)+(n-2)+(n-3)+...+(2) +(1) or(sum of all #from 0 to N) = (1)+ (2) + (3) + (4)+...+(n-1)+(n)the two different sums are aligned by columns. now add the two colunms accordingly and you'll get2x(sum of all #from 0 to N)=(n+1)+(n+1)+...+(n+1) (n+1)is added n timesso2x(sum of all #from 0 to N) =n(n+1)(sum of all #from 0 to N) =n(n+1)/2so (sum of 5 to 100) = (sum of 0 to 100)- (sum of 0 to 5)=100(101)/2 - 5(6)/2 = 5050 - 15 = 5035

An array is very useful to easily handle a large set of data, or a data set that has a variable size. Here is an example: To add 100 numbers, without an array, you would have to store data to 100 different variables, and then: sum = 0; sum += item001; sum += item002; sum += item003; sum += item004; ... sum += item100; ... a total of 100 lines. To add 1000 items, you need 1000 lines. If you don't know the number of items in advance, it is even worse, because you need to execute every single line conditionally. With an array, the above example gets much more compact: sum = 0; for (i = 0; i < 100; i++) sum += items[i];An array is very useful to easily handle a large set of data, or a data set that has a variable size. Here is an example: To add 100 numbers, without an array, you would have to store data to 100 different variables, and then: sum = 0; sum += item001; sum += item002; sum += item003; sum += item004; ... sum += item100; ... a total of 100 lines. To add 1000 items, you need 1000 lines. If you don't know the number of items in advance, it is even worse, because you need to execute every single line conditionally. With an array, the above example gets much more compact: sum = 0; for (i = 0; i < 100; i++) sum += items[i];An array is very useful to easily handle a large set of data, or a data set that has a variable size. Here is an example: To add 100 numbers, without an array, you would have to store data to 100 different variables, and then: sum = 0; sum += item001; sum += item002; sum += item003; sum += item004; ... sum += item100; ... a total of 100 lines. To add 1000 items, you need 1000 lines. If you don't know the number of items in advance, it is even worse, because you need to execute every single line conditionally. With an array, the above example gets much more compact: sum = 0; for (i = 0; i < 100; i++) sum += items[i];An array is very useful to easily handle a large set of data, or a data set that has a variable size. Here is an example: To add 100 numbers, without an array, you would have to store data to 100 different variables, and then: sum = 0; sum += item001; sum += item002; sum += item003; sum += item004; ... sum += item100; ... a total of 100 lines. To add 1000 items, you need 1000 lines. If you don't know the number of items in advance, it is even worse, because you need to execute every single line conditionally. With an array, the above example gets much more compact: sum = 0; for (i = 0; i < 100; i++) sum += items[i];

100

#include<stdio.h> #include<conio.h> void main() { int i,sum=0; clrscr(); for(i=2;i<=100;i+2) { sum=sum+i; } printf("sum is %d",sum); getch(); }

#include<stdio.h> #include<conio.h> void main() { clrscr(); int i,sum=0; for(i=2;i<=100;i=i+2) { sum=sum+i; } printf("sum of even no.%d",sum); getch(); }

public static void main(String[] args) { int count = 0; int sum = 0; for(int i = 100; i < 200; i++) { if(i%7 == 0){ System.out.println(i); count++; sum = sum + i; } } System.out.println("Number of values divisble by 7 is: " + count); System.out.println("Sum of the values divisible by 7 is: " + sum); }

#include using std::cout;using std::endl;int main(){int sum = 0;cout

#include using std::cout;using std::endl;int main(){const int numToAdd = 100;int sum = 0;for (int i = 1; i

#include<stdio.h>int main () { int sum = 0; for (int odd=3; odd<100; odd+=2) { printf ("%d\n", odd); sum += odd; } printf ("\nSum = %d\n", sum); return 0; }

Increment your counter two at a time. Example, for n = 100: n = 100; sum = 0; for (int i = 1; i <= n; i+=2) sum += i; Another option (less efficient) is to loop through ALL integers, and check whether the number is odd: n = 100; sum = 0; for (int i = 1; i <= n; i++) { if (i % 2 == 1) sum += i; } Or: if (min%2==0) min= min+1; if (max%2==0) max= max-1; sum = ((max-min)/2 + 1) * (min+max) / 2;

#include #define NUM 100 //since prog is to be written for adding 100 naturalint main(){int i,sum=0;for(i=1;i

If the numbers are consecutive, use a for loop, and just add the counter variable. The following example (Java language) will add the numbers 1, 2, ... 100:int sum = 0;for (int i = 1; i

int num = 0; int sum = 0; // 105 is the first integer greater than 100 which is evenly divisible by 7 for(int i = 104; i < 200; i+=7) {++num;sum += i; }