Scripting Classroomnotes 05/May/2023

Floating point arthimetic

Solving problems in Hacker Rank

  • Refer Here
  • Flowchart to figure out if the number is prime or not
    Preview
  • Program
#!/bin/bash
read -p "Enter Number: " number
index=2
while [[ $index -lt number ]]
do
    REMAINDER=$((number%index))
    if [[ $REMAINDER -eq 0 ]]; then
        echo "$number is not prime"
        exit 1
    fi
    index=$((index+1))
done
echo "$number is prime"
  • Sum of numbers
Sample input:
353 => 3+5+3 => 11 => 1+1 => 2
1414 => 1+4+1+4 => 10 => 1+0 => 1
414 => 4+1+4 => 9

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube