Given a number n, use the if statement to print "Big" (without quotes) if the given number is greater than 100. The statement "Number" (without quotes) will be printed regardless.
Note: Follow Sample cases for the output format. After printing move the cursor to the next line.
Examples:
Input: n = 10
Output:
Number
Explanation: 10 is less than 100, so we don't print Big and Number will be printed by default.Input: n = 101
Output:
Big
Number
Explanation: 101 is greater than 100, so we print Big and Number will be printed by default in the next line.
If-Else Statement - O(1) Time and O(1) Space
The idea is to use an if-else statement to check whether n is greater than 100.
Working of Approach:
- Take the input number n.
- Check whether n > 100.
- If true, print "Big".
- Otherwise, skip printing "Big".
- Print "Number" in both cases.
#include <iostream>
int main() {
int n = 101;
// Check if n is greater than 100
if (n > 100) {
std::cout << "Big" << std::endl;
}
else {
// Number is printed when n is not greater than 100
std::cout << "Number" << std::endl;
return 0;
}
// Print Number when n is greater than 100
std::cout << "Number" << std::endl;
return 0;
}
#include <stdio.h>
int main() {
int n = 101;
// Check if n is greater than 100
if (n > 100) {
printf("Big\n");
}
else {
// Number is printed when n is not greater than 100
printf("Number\n");
return 0;
}
// Print Number when n is greater than 100
printf("Number\n");
return 0;
}
public class Main {
public static void main(String[] args) {
int n = 101;
// Check if n is greater than 100
if (n > 100) {
System.out.println("Big");
}
else {
// Number is printed when n is not greater than 100
System.out.println("Number");
return;
}
// Print Number when n is greater than 100
System.out.println("Number");
}
}
n = 101
# Check if n is greater than 100
if n > 100:
print("Big")
else:
# Number is printed when n is not greater than 100
print("Number")
return
# Print Number when n is greater than 100
print("Number")
using System;
class Program {
static void Main() {
int n = 101;
// Check if n is greater than 100
if (n > 100) {
Console.WriteLine("Big");
}
else {
// Number is printed when n is not greater than 100
Console.WriteLine("Number");
return;
}
// Print Number when n is greater than 100
Console.WriteLine("Number");
}
}
let n = 101;
// Check if n is greater than 100
if (n > 100) {
console.log("Big");
}
else {
// Number is printed when n is not greater than 100
console.log("Number");
return;
}
// Print Number when n is greater than 100
console.log("Number");
Output
Big Number
If Statement - O(1) Time and O(1) Space
The idea is to use an if statement to print "Big" only when n is greater than 100. Then, print "Number" unconditionally.
Working of Approach:
- Take the input number n.
- Check whether n > 100.
- If true, print "Big".
- Skip the if block if the condition is false.
- Print "Number" in every case.
#include <iostream>
using namespace std;
int main()
{
int n = 101;
// Print Big if n is greater than 100
if (n > 100)
{
cout << "Big\n";
}
// Print Number regardless of the condition
cout << "Number\n";
return 0;
}
#include <stdio.h>
int main()
{
int n = 101;
// Print Big if n is greater than 100
if (n > 100)
{
printf("Big\n");
}
// Print Number regardless of the condition
printf("Number\n");
return 0;
}
public class GFG {
public static void main(String[] args)
{
int n = 101;
// Print Big if n is greater than 100
if (n > 100) {
System.out.println("Big");
}
// Print Number regardless of the condition
System.out.println("Number");
}
}
n = 101
# Print Big if n is greater than 100
if n > 100:
print("Big")
# Print Number regardless of the condition
print("Number")
using System;
class GFG {
static void Main()
{
int n = 101;
// Print Big if n is greater than 100
if (n > 100) {
Console.WriteLine("Big");
}
// Print Number regardless of the condition
Console.WriteLine("Number");
}
}
let n = 101;
// Print Big if n is greater than 100
if (n > 100) {
console.log("Big");
}
// Print Number regardless of the condition
console.log("Number");
Output
Big Number