Question

In: Computer Science

1. Write a shell code that prints the integers from 80-90 2. Write a shell code...

1. Write a shell code that prints the integers from 80-90

2. Write a shell code that prints the sum of odd integers that are inputted by the user

3. Write a shell code that reads a set of integers {125, 0, 122, 129, 0, 117} and prints {125, 122, 129, 117}

Programming Language: Linux

Solutions

Expert Solution

1. Below is shell code that prints the integers from 80-90:

#Method 1
seq 80 90
#Method 2
for ((a=80; a <= 90 ; a++))
do
   echo $a
done

Output:

2. Below is a shell code that prints the sum of odd integers that are inputted by the user.

first_num=0
second_num=0

#Read first odd number:
read -p "Enter the first odd number --> " first_num

#Read second odd number:
read -p "Enter the second number -> " second_num

echo "Sum is: = $((first_num + second_num))"

Output:

3. Below is a shell code that reads a set of integers {125, 0, 122, 129, 0, 117} and prints {125, 122, 129, 117}

#Reads a set of integers
read -a arr

#Print integers except 0 from list
for elem in ${arr[@]}
do 
    if (( elem != 0 ))
    then
            echo -n $elem "" 
    fi
done

Output:


Related Solutions

Write a program that uses a while statement to read integers from the user and prints...
Write a program that uses a while statement to read integers from the user and prints the sum, average, and largest of these numbers. The input should terminate if the user enters 999. The average should be output with 4 digits of precision. c++ please ASAP
Write a method called printIsMultiple that receives a pair of integers and prints true if the...
Write a method called printIsMultiple that receives a pair of integers and prints true if the second is a multiple of the first; false, otherwise
Write code that takes the size of their foot from user and prints out suggested sandal...
Write code that takes the size of their foot from user and prints out suggested sandal size. Shoe Range Sandal Size <= 5 (inclusive) Small 5 ~ 9 (inclusive) Medium 9 ~ 12 (inclusive) Large above 12 X-Large example: Please enter your shoe size: (user types 6.5) Your sandal size is Medium.
Given an array of integers and the size of the array, write a function findDuplicate which prints the duplicate element from the array.
C++ Programming using iostream and namespace stdGiven an array of integers and the size of the array, write a function findDuplicate which prints the duplicate element from the array. The array consists of all distinct integers except one which is repeated. Find and print the repeated number. If no duplicate is found, the function should print -1. void findDuplicate (int [ ], int)Example 1: Given array: {2,3,5,6,11,20,4,8,4,9} Output: 4 Example 2: Given array: {1,3,5,6,7,8,2,9} Output: -1
Write a program that initializes an array of 6 random integers and then prints 4 lines...
Write a program that initializes an array of 6 random integers and then prints 4 lines of output, containing the following: 1. Only the first and last element 2. Every element at an odd index 3. Every odd element 4. All elements in reverse order
Code is in C Write a program that reads integers from stdin. Once it reaches the...
Code is in C Write a program that reads integers from stdin. Once it reaches the * end of the input, it prints the smallest absolute value among those * of the numbers it read. * * For example, if * 4, 6 -3, 3, -2, 13, -4 * are read from stdin, the program should print 2. * * If the end of file is reached before any integer is seen, the * number printed should be INT_MAX (defined...
write code to count the number of odd integers in an array of 100 random integers...
write code to count the number of odd integers in an array of 100 random integers in the range [0,99].
1. Write a Python program that performs the following: 2. Defines an array of integers from...
1. Write a Python program that performs the following: 2. Defines an array of integers from 1 to 10. The numbers should be filled automatically without the need for user inputs 3. Find the sum of the numbers that are divisible by 3 (i.e., when a number is divided by 3, the remainder is zero) 4. Swap the positions of the maximum and minimum elements in the array. First, you need to find the maximum element as shown in the...
C++ code please: Write a program that first gets a list of integers from input. The...
C++ code please: Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, which indicates how much to multiply the array by. Finally, print out the entire array with each element multiplied by the last input. Assume that the list will always contain less than 20 integers. Ex: If the input is 4 4 8 -4 12...
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> For this project, you are to: 1) You should validate any data coming from the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT