Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 8 years ago

calculate the sum of integers from 1 to 100?

I am new to shell programming, i need to come up a bash script that calculates the sum of all integers from 1 to 100. Can anyone help me?

4 Answers

Relevance
  • 8 years ago
    Favorite Answer

    !/bin/bash

    echo "This script will add all integers from 1 to 100"

    RESULT = 0

    for (( c=1; c<=100; c++ ))

    do

    $RESULT = $RESULT + c

    done

    echo "The result is $RESULT"

    ===========

    or something like that, I'm 99% sure.

    Source(s): im a programming student
  • 8 years ago

    I apologize i do not know bash, but I know several other languages.

    you will need a for loop

    something like this:

    sum=0

    for x = 1 to 100

    sum = sum + x

    end for

  • Cronin
    Lv 6
    8 years ago

    Sorry but you don't need a script for that...

    the answer is simply (100*101)/2

    if you must loop it use

    sum=0;for i in {1..100};do sum=$(( sum+i ));done;echo $sum

  • 8 years ago

    No.

    Source(s): Professor @UniSA
Still have questions? Get your answers by asking now.