K

@Khushi_Rana

Shell Script swapping 3 variable without temporary variable

Bash
2 years ago
#!/bin/bash # Assign initial values to the variables a=30 b=40 c=45 echo "Before swapping a number: a = $a, b = $b, c = $c" # Swap the values a=$((a ^ b ^ c))

Shell script to print pyramid

Bash
2 years ago
#!/bin/bash read -p "Enter the number of rows for the pyramid: " rows rows=4 # Loop to iterate through each row for ((i = 1; i <= rows; i++)); do # Loop to print spaces for ((j = i; j <= rows; j++)); do echo -n " " done

Child Process

C
2 years ago
#include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { pid_t pid; pid = fork(); // Create a child process if (pid < 0) { // Error handling

Even number or odd number

Bash
2 years ago
#!/bin/bash read -p "Enter a number :" a a=7 if [ $((a % 2)) -eq 0 ]; then echo "Even number" else echo "Odd number" fi

Biggest number

Bash
2 years ago
#!/bin/bash num1=7 num2=6 num3=2 max=$num1 if [ $num2 -gt $max ]; then max=$num2 fi if [ $num3 -gt $max ]; then max=$num3

Palidrome

Bash
2 years ago
#!/bin/bash num=676 original_num=$num rev=0 while [ $num -gt 0 ]; do reminder=$((num % 10)) rev=$((rev * 10 + reminder)) num=$((num / 10)) done

palidrome

Bash
2 years ago
#!/bin/bash echo "Enter a number:" read number reverse=0 original= $number while [ $number -nc 0 ] do remainder= $(($number%10)) reverse=$(($reverse*10+$remainder)) number=$(($number/10))

Shell script to print array

Bash
2 years ago
#!/bin/bash arr=("1","2","3","4") echo -n "Array elements: $arr"

Factorial of Number

Bash
2 years ago
#!/bin/bash num=7 fact=1 while [ $num -gt 1 ] do fact=$(( fact*num)) num=$((num-1)) done echo "factorial in $fact"

Adding of Two Numbers

Bash
2 years ago
#!/bin/bash a=20 b=30 sum=$(($a+$b)) echo "The sum is $sum"

Swap two variable without using third variable

Bash
2 years ago
#!/bin/bash a=5 b=10 #swapping a=$((a+b)) b=$((a+b)) a=$((a-b)) echo "After swapping, number are:" echo "first=$a, second=$b"