Sponsored Content
Homework and Emergencies Homework & Coursework Questions Sum of even numbers from 0 to 100 script Post 303031625 by Nastybutler on Sunday 3rd of March 2019 02:41:08 AM
Old 03-03-2019
Sum of even numbers from 0 to 100 script

1. The problem statement, all variables and given/known data:

Write a shell script that finds and display the sum of even positive integers from 0 to 100. Use the while control structure. Show your script and a sample run.

2. Relevant commands, code, scripts, algorithms:

Must us a while loop

3. The attempts at a solution (include all code and scripts):

This is one attempt:
Code:
for i in {0..100}
do
        (( b = $i % 2 ))
        if [ $b -ne 0 ]
        then
        echo $i
fi
done

Another attempt, just trying to get somewhere and have it print something, but with this one I was getting a syntax error..

Code:
sum=0
while (( i=0; i<=100; i++ ));do
        if (( $i % 2 )); then
        echo $i is odd
else
        echo %i is even
fi
done

Portland Community College, Portland, OR, United States, Shawli Sengupta, CS-140U-0-14858 - Intro to UNIX/Linux
I cannot add the URL to the course because I do not have enough post on this forum.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to sum numbers in column

Hi, i want to sum all nubers in one column. Example: 12.23 11 23.01 3544.01 I'm trying to do this in awk, but it doesn't work properly. Seems like awk is summing only integers, for example: 12 11 23 3544 It cuts off numbers after dot. I used this command: akw /text/ file.txt |nawk... (1 Reply)
Discussion started by: iahveh
1 Replies

2. Shell Programming and Scripting

sum numbers from stdout

hello im looking for short way to sum numbers from stdout the way i found to do it is to long for me i wander if there is shorter way to do it ok it 2 stage action this will make the list of number in to file sum.txt grep -c include *.c | awk '{l=split($0,a,":");print a;}' > sum.txt this... (1 Reply)
Discussion started by: umen
1 Replies

3. Shell Programming and Scripting

Shell script to find the sum of first n Fibonacci numbers

pls give me the solution for this i need it for my exam pls pls pls Shell script to find the sum of first n Fibonacci numbers (1 Reply)
Discussion started by: Kshitija
1 Replies

4. Homework & Coursework Questions

Help with shell script to find sum of first n numbers of Fibonacci series

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Shell script to find sum of first n numbers of Fibonacci series 2. Relevant commands, code, scripts,... (0 Replies)
Discussion started by: Kshitija
0 Replies

5. Shell Programming and Scripting

Finding the sum of two numbers

cat *.out |grep "<some text>" | awk '{print $6}' For ex,This will reutrn me 11111 22222 is it possible to add these two numbers in the above given command itself?I can write this to a file and find the sum. But I prefer to this calculation in the above given line itself. Any... (3 Replies)
Discussion started by: prasperl
3 Replies

6. Shell Programming and Scripting

getting the sum of numbers

I basically have a file where I had to do a bunch of greps to get a list of numbers example: a file called numbers.txt 10000 10000 superman 10000 batman 10000 10000 grep '100' * | 10000 10000 10000 10000 10000 (2 Replies)
Discussion started by: zerofire123
2 Replies

7. Shell Programming and Scripting

Sum Numbers from different files

Hi All, I need to print the sum of numbers from different files. Input files: file1.out 10 20 30 file2.out 10 20 30 (5 Replies)
Discussion started by: saint2006
5 Replies

8. Shell Programming and Scripting

Script Shell: Count The sum of numbers in a file

Hi all; Here is my file: V1.3=4 V1.4=5 V1.1=3 V1.2=6 V1.3=6 Please, can you help me to write a script shell that counts the sum of values in my file (4+5+3+6+6) ? Thank you so much for help. Kind regards. (3 Replies)
Discussion started by: chercheur111
3 Replies

9. Shell Programming and Scripting

Shell script count lines and sum numbers from multiple files

I want to count the number of lines, I need this result be a number, and sum the last numeric column, I had done to make this one at time, but I need to make this for a crontab, so, it has to be an script, here is my lines: It counts the number of lines: egrep -i String file_name_201611* |... (5 Replies)
Discussion started by: Elly
5 Replies

10. UNIX for Beginners Questions & Answers

Sum even numbers from 1 to 100

I need help with this assignment. I'm very new to using UNIX/LINUX, and my only previous experience with programing anything is using python. We are writing scripts using vim, and this one I'm stumped on. "Write a shell script that finds and display the sum of even positive integers from 0 to... (5 Replies)
Discussion started by: Nastybutler
5 Replies
CPAN(1) 						 Perl Programmers Reference Guide						   CPAN(1)

NAME
cpan - easily interact with CPAN from the command line SYNOPSIS
# with arguments and no switches, installs specified modules cpan module_name [ module_name ... ] # with switches, installs modules with extra behavior cpan [-cfimt] module_name [ module_name ... ] # without arguments, starts CPAN.pm shell cpan # without arguments, but some switches cpan [-ahrvACDLO] DESCRIPTION
This script provides a command interface (not a shell) to CPAN. At the moment it uses CPAN.pm to do the work, but it is not a one-shot com- mand runner for CPAN.pm. Meta Options These options are mutually exclusive, and the script processes them in this order: [hvCAar]. Once the script finds one, it ignores the others, and then exits after it finishes the task. The script ignores any other command line options. -a Creates the CPAN.pm autobundle with CPAN::Shell->autobundle. -A module [ module ... ] Shows the primary maintainers for the specified modules -C module [ module ... ] Show the "Changes" files for the specified modules -D module [ module ... ] Show the module details. This prints one line for each out-of-date module (meaning, modules locally installed but have newer versions on CPAN). Each line has three columns: module name, local version, and CPAN version. -L author [ author ... ] List the modules by the specified authors. -h Prints a help message. -O Show the out-of-date modules. -r Recompiles dynamically loaded modules with CPAN::Shell->recompile. -v Print the script version and CPAN.pm version. Module options These options are mutually exclusive, and the script processes them in alphabetical order. It only processes the first one it finds. c Runs a `make clean` in the specified module's directories. f Forces the specified action, when it normally would have failed. i Installed the specified modules. m Makes the specified modules. t Runs a `make test` on the specified modules. Examples # print a help message cpan -h # print the version numbers cpan -v # create an autobundle cpan -a # recompile modules cpan -r # install modules ( sole -i is optional ) cpan -i Netscape::Booksmarks Business::ISBN # force install modules ( must use -i ) cpan -fi CGI::Minimal URI TO DO
BUGS
* none noted SEE ALSO
Most behaviour, including environment variables and configuration, comes directly from CPAN.pm. SOURCE AVAILABILITY
This source is part of a SourceForge project which always has the latest sources in CVS, as well as all of the previous releases. http://sourceforge.net/projects/brian-d-foy/ If, for some reason, I disappear from the world, one of the other members of the project can shepherd this module appropriately. CREDITS
Japheth Cleaver added the bits to allow a forced install (-f). Jim Brandt suggest and provided the initial implementation for the up-to-date and Changes features. Adam Kennedy pointed out that exit() causes problems on Windows where this script ends up with a .bat extension AUTHOR
brian d foy, "<bdfoy@cpan.org>" COPYRIGHT
Copyright (c) 2001-2006, brian d foy, All Rights Reserved. You may redistribute this under the same terms as Perl itself. perl v5.8.9 2009-04-13 CPAN(1)
All times are GMT -4. The time now is 06:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy