write a c program to Findthe smallest odd number in given set of numbers
Answers
Answer:
Approach: There can be two cases depending on the value of N.
Case 1 : If N = 1 then answer will be 1.
Case 2 : If N != 1 then answer will be (10^(n-1)) + 1 because the series of the smallest odd numbers will go on like: 1, 11, 101, 1001, 10001, 100001, ….
Below is the implementation of the above approach:
// C++ implementation of the above approach
#include <bits/stdc++.h>
using namespace std;
// Function to return smallest odd
// with n digits
int smallestOdd(int n)
{
if (n == 1)
return 1;
return pow(10, n - 1) + 1;
}
// Driver Code
int main()
{
int n = 4;
cout << smallestOdd(n);
return 0;
}
Answer:
// C++ implementation of the above approach
#include <bits/stdc++.h>
using namespace std;
// Function to return smallest odd
// with n digits
int smallestOdd(int n)
{
if (n == 1)
return 1;
return pow(10, n - 1) + 1;
}
// Driver Code
int main()
{
int n = 4;
cout << smallestOdd(n);
return 0;
Explanation: