Computer Science, asked by vasudev2658, 9 months ago

Write a shell script which ask user an integer number of length l and find the largest digit in a number for required purpose

Answers

Answered by subhashinerout
0

Answer:

Largest and smallest digit of a number

Given a number N. The task is to find the largest and the smallest digit of the number.

Examples :

Input : N = 2346

Output : 6 2

6 is the largest digit and 2 is samllest

Input : N = 5

Output : 5 5

Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach: An efficient approach is to find all digits in the given number and find the larg

Answered by qwvilla
0

// C++ program to find the largest digit of a number

#include <bits/stdc++.h>

using namespace std;

void findLargest(int num)

{

int largestDigit = 0;

int digit;

while(num)

{

digit = num%10;

// Finding the largest digit

num = num/10;

}

cout << "Largest Digit: " << largestDigit << endl;

}

// Driver Code

int main()

{

int num1 = 238627;

cout << "num1: " << num1 << endl;

findLargest(num1);

int num2 = 34552;

cout << "num2: " << num2 << endl;

findLargest(num2);

int num3 = 123;

cout << "num3: " << num3 << endl;

findLargest(num3);

int num4 = 45672;

cout << "num4: " << num4 << endl;

findLargest(num4);

int num5 = 76567;

cout << "num5: " << num5 << endl;

findLargest(num5);

return 0;

}

#SPJ3

Similar questions