C++ Program to Find GCD

Finding the Greatest Common Divisor (GCD) of two numbers is a fundamental problem in mathematics and computer science, often introduced early in programming courses to illustrate algorithms, loops, and decision-making processes. The GCD of two numbers is the largest positive integer that divides both numbers without leaving a remainder. For example, the GCD of 8 and 12 is 4.

In programming, there are several ways to calculate the GCD, with the Euclidean algorithm being one of the most efficient and commonly used methods. This algorithm is based on the principle that the GCD of two numbers also divides their difference. In C++, implementing the Euclidean algorithm to find the GCD of two numbers can be both a straightforward and insightful exercise.

Introduction to the Euclidean Algorithm

The Euclidean algorithm iteratively reduces the problem of finding the GCD of two numbers until it reaches a case where the GCD is apparent. The algorithm is based on two key observations:

  1. GCD(a, b) = GCD(b, a % b): The GCD of two numbers a and b is the same as the GCD of b and the remainder of a divided by b.
  2. GCD(a, 0) = a: The GCD of any number a and 0 is a.

These properties allow us to repeatedly apply the operation a % b (find the remainder of a divided by b) and swap the numbers until one of them becomes zero. The other number, at that point, is the GCD.

Implementing the GCD Algorithm in C++

Here is a simple implementation of the Euclidean algorithm in C++ to find the GCD of two numbers:

#include <iostream>

using namespace std;

// Function to find the GCD of two integers using the Euclidean algorithm

int gcd(int a, int b) {

    while(b != 0) {

        int remainder = a % b;

        a = b;

        b = remainder;

    }

    return a; // When b is 0, a is the GCD

}

int main() {

    int num1, num2;

    // Prompt the user to enter two numbers

    cout << “Enter two integers: “;

    cin >> num1 >> num2;

    // Ensure the numbers are positive

    if(num1 < 0 || num2 < 0) {

        cout << “Please enter positive integers.” << endl;

        return 1;

    }

    // Calculate and display the GCD

    cout << “The GCD of ” << num1 << ” and ” << num2 << ” is ” << gcd(num1, num2) << “.” << endl;

    return 0;

}

 

Explanation of the Program

  • Input:

The program begins by asking the user to input two integers. These numbers are the ones for which we want to find the GCD.

  • Validation:

It’s a good practice to validate user input. Here, we ensure that the inputs are positive integers, as the GCD concept applies to positive numbers.

  • GCD Calculation:

The gcd function implements the core logic of the Euclidean algorithm. It repeatedly applies the modulo operation to reduce the problem size until one of the numbers becomes zero. The other number, at this point, is the GCD.

  • Output:

Finally, the program outputs the GCD of the two input numbers.

C++ Program to Find Factorial of a Number

Calculating the factorial of a number is a common programming challenge that highlights several key concepts in computer science and software development, including recursion, loops, and handling user input. The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For instance, 5! = 5×4×3×2×1 = 120.

Introduction to Factorial Calculation

The factorial operation is foundational in combinatorics, probability, and many areas of mathematics and computer science. Its calculation through programming serves not only as a practice in implementing mathematical formulas but also in choosing the appropriate algorithms and structures for a given problem. C++ offers various means to tackle factorial calculation, each with its advantages and considerations.

Setting Up a Basic C++ Program

A C++ program begins with including necessary libraries and using directives:

#include <iostream>

#include <limits>

using namespace std;

Here, iostream is included for input and output operations, and limits might be used for handling data type limits effectively.

Soliciting User Input

Engaging the user and obtaining the number for which to calculate the factorial is the first step:

int main() {

    unsigned int n;

    cout << “Enter a non-negative integer: “;

    cin >> n;

    if(cin.fail() || n > 12) { // Simple validation to prevent overflow in our example

        cout << “Invalid input. Please enter a non-negative integer less than or equal to 12.” << endl;

        return 1; // Exit the program indicating failure

    }

The above code block includes a simple validation check to ensure the input is within a range that prevents overflow for the chosen data type (unsigned int). This is crucial for maintaining the program’s robustness and correctness.

Implementing Factorial Calculation

  • Loop-Based Approach

One way to calculate the factorial of a number is by using a loop. This method iterates from 1 to n, multiplying each number by a running total:

    unsigned long long factorial = 1; // Initialize to 1 as we are multiplying

    for(unsigned int i = 2; i <= n; ++i) {

        factorial *= i;

    }

    cout << n << “! = ” << factorial << endl;

This loop-based method is straightforward and illustrates the iterative approach to solving problems.

  • Recursive Approach

Alternatively, factorial calculation lends itself well to a recursive solution, where a function calls itself with a simpler version of the original problem:

unsigned long long factorial(unsigned int n) {

    if (n <= 1) return 1; // Base case

    else return n * factorial(n – 1); // Recursive case

}

To integrate this into our program, we would modify the main function to call factorial(n) and display the result.

Analyzing the Approaches

Both iterative and recursive approaches have their merits. The iterative solution is straightforward, easy to understand, and efficient in terms of memory usage since it avoids the overhead of multiple function calls. On the other hand, the recursive solution offers a cleaner, more elegant code that closely mirrors the mathematical definition of factorial. However, recursion requires additional memory for each function call’s context, and excessive recursion can lead to stack overflow errors in languages like C++ that do not optimize for tail recursion.

Handling Large Numbers and Efficiency

Calculating factorials for even moderately large numbers quickly results in values that exceed the storage capacity of standard integer types in C++. This limitation highlights the importance of considering data types and potential overflow issues in algorithmic design and implementation. For larger numbers, one might consider using libraries designed for arbitrary-precision arithmetic, though this introduces additional complexity and potential performance considerations.

C++ Program to Display Prime Numbers Between Two Intervals

Prime Numbers are fundamental elements in mathematics and computer science, representing numbers greater than 1 that have no divisors other than 1 and themselves. The task of identifying prime numbers between two intervals highlights key programming concepts such as loops, conditionals, and functions, and is an excellent example of applying computational thinking to solve mathematical problems.

  • Understanding the Task

Displaying prime numbers between two intervals involves iterating through all the numbers in the specified range and checking each number to determine if it is prime. This task is computationally intensive, especially for large intervals, due to the nature of prime number determination. Hence, optimizing the prime check process is crucial to improving the program’s efficiency.

Optimized Approach to Prime Checking

The standard approach to check if a number is prime involves dividing the number by all smaller numbers up to 2. This method can be optimized by observing that:

  1. No prime number is divisible by any number greater than its square root.
  2. Numbers less than 2 are not prime.

Based on these observations, the prime checking function can significantly reduce the number of iterations, enhancing performance.

Implementing the Program

The program will consist of two parts:

  1. A function to check if a number is prime.
  2. The main function that iterates through the range, uses the prime-checking function, and displays the primes.

C++ Program to Display Prime Numbers Between Two Intervals

#include <iostream>

#include <cmath> // For the sqrt() function

using namespace std;

// Function to check if a number is prime

bool isPrime(int num) {

    if (num < 2) return false; // Numbers less than 2 are not prime

    for (int i = 2; i <= sqrt(num); ++i) {

        if (num % i == 0) return false; // If divisible, not prime

    }

    return true; // Number is prime

}

int main() {

    int start, end;

    // Prompt the user for the interval

    cout << “Enter two numbers (intervals): “;

    cin >> start >> end;

    cout << “Prime numbers between ” << start << ” and ” << end << ” are: ” << endl;

    // Iterate through the range and display prime numbers

    for (int num = start; num <= end; ++num) {

        if (isPrime(num)) {

            cout << num << ” “;

        }

    }

    return 0;

}

 

Program Explanation

  • Prime Checking Function (isPrime):

This function takes an integer as input and returns true if the number is prime, otherwise false. It efficiently checks divisibility only up to the square root of the number, leveraging the mathematical insight that factors of a number are always found in pairs, one less than and one greater than the square root of the number.

  • Main Function:

The main function begins by asking the user to input two numbers, defining the interval within which to find prime numbers. It then iterates through each number in this interval, using the isPrime function to check for primality. Prime numbers are displayed to the user.

  • Efficiency and Optimization:

The program is optimized for efficiency by reducing the number of divisions needed to determine if a number is prime. This is critical for larger numbers and wider ranges, where naive approaches might lead to significantly longer computation times.

C++ Program to Display Factors of a Natural Number

Displaying the factors of a natural number involves finding all the numbers that divide the given number without leaving a remainder. Factors are integral to various mathematical calculations and are particularly interesting when exploring number theory, prime numbers, and algorithms that involve divisibility.

In this context, a factor of a number n is any integer i where n % i == 0. To find all such numbers, a straightforward approach involves iterating through all integers from 1 to n and checking if n % i == 0. If the condition holds true, i is a factor of n.

Let’s write a C++ program that takes a natural number as input from the user and displays all its factors:

#include <iostream>

using namespace std;

// Function to print the factors of a given number n

void printFactors(int n) {

    cout << “The factors of ” << n << ” are: “;

    for (int i = 1; i <= n; ++i) {

        if (n % i == 0) {

            cout << i << ” “;

        }

    }

    cout << endl;

}

int main() {

    int number;

    cout << “Enter a natural number: “;

    cin >> number;

    // Check for natural number input

    if (number < 1) {

        cout << “Please enter a natural number greater than 0.” << endl;

    } else {

        printFactors(number);

    }

    return 0;

}

This program begins by prompting the user to enter a natural number. It checks whether the input is a natural number (i.e., an integer greater than 0). If the check passes, the program proceeds to find and print all the factors of the input number using the printFactors function.

Within printFactors, the program iterates from 1 to n, inclusive. For each number i in this range, it checks if n % i == 0. If the condition is true, it means i is a divisor (or factor) of n, and the program prints i.

This method is simple and effective for small to moderately sized integers. However, for very large numbers, more efficient algorithms may be necessary to reduce computational time, such as only checking up to the square root of n and adding both the divisor and the quotient when applicable.

C++ Program to Display Armstrong Numbers Between 1 to 1000

Displaying Armstrong numbers within a specific range, such as from 1 to 1000, is a common programming task that showcases the application of loops, conditionals, and arithmetic operations in C++. Armstrong numbers, as previously discussed, are numbers that equal the sum of their own digits each raised to the power of the number of digits in the number. This property makes them particularly interesting from both mathematical and programming perspectives.

To create a program that identifies and displays Armstrong numbers within a given range, the steps are as follows:

  1. Loop through the Range:

Iterate over each number in the specified range (1 to 1000 in this case).

  1. Check for Armstrong Number:

For each number, determine if it is an Armstrong number.

  1. Display the Number:

If a number is identified as an Armstrong number, display it.

This process requires a function to check if a given number is an Armstrong number, similar to what was outlined previously.

C++ Program

 

#include <iostream>

#include <cmath>

using namespace std;

// Function to calculate the number of digits in a number

int countDigits(int n) {

    int count = 0;

    while (n != 0) {

        count++;

        n /= 10;

    }

    return count;

}

// Function to check if a number is an Armstrong number

bool isArmstrong(int num) {

    int originalNum = num;

    int numOfDigits = countDigits(num);

    int sumOfPowers = 0;

    while (num != 0) {

        int digit = num % 10;

        sumOfPowers += pow(digit, numOfDigits);

        num /= 10;

    }

    return sumOfPowers == originalNum;

}

int main() {

    cout << “Armstrong numbers between 1 to 1000 are:” << endl;

    for (int num = 1; num <= 1000; num++) {

        if (isArmstrong(num)) {

            cout << num << endl;

        }

    }

    return 0;

}

 

Explanation

  1. Counting Digits (countDigits function):

This function, as before, calculates the number of digits in a given number. This is crucial for determining the power to which each digit should be raised.

  1. Armstrong Number Check (isArmstrong function):

This function determines if a given number is an Armstrong number by comparing it to the sum of its digits each raised to the power of the number of digits in the number.

  1. Main Logic:

The main function iterates through numbers from 1 to 1000, utilizing the isArmstrong function to check for Armstrong numbers. When an Armstrong number is found, it is printed out.

C++ Program to Check Whether a Number is Prime or Not

Prime Number is a natural number greater than 1 that has no positive divisors other than 1 and itself. In other words, a prime number is a number that cannot be exactly divided by any number other than 1 and itself. The task of determining whether a given number is prime is fundamental in various fields of computer science, cryptography, and mathematical computation.

Understanding Prime Numbers

Before delving into the program, it’s essential to understand the characteristics of prime numbers and the logic used to identify them. A prime number:

  1. Must be greater than 1.
  2. Has exactly two distinct positive divisors: 1 and itself.

For example, the numbers 2, 3, 5, 7, 11, and 13 are prime because each can only be divided by 1 and the number itself without leaving a remainder. On the other hand, numbers like 4, 6, 8, 9, and 10 are not prime because they have more than two divisors.

Algorithm for Checking Prime Numbers

The simplest method to check if a number is prime is to try dividing it by all numbers from 2 to the number itself (exclusive) and check for a remainder. If any division operation results in no remainder, the number is not prime. However, this method can be optimized. Since a factor of a number n cannot be more than n/2 (except for n itself), you only need to check up to n/2. Further optimization notes that a factor of n cannot be more than √n, significantly reducing the number of checks needed.

C++ Program to Determine Prime Numbers

Let’s now look at a C++ program that implements the optimized approach to check if a given number is prime.

#include <iostream>

#include <cmath> // For the sqrt() function

using namespace std;

// Function to check if a number is prime

bool isPrime(int num) {

    // Handle base cases: if num is less than 2, it’s not prime

    if (num < 2) {

        return false;

    }

    // Only need to check for divisors up to the square root of num

    for (int i = 2; i <= sqrt(num); ++i) {

        // If num is divisible by any number between 2 and sqrt(num), it’s not prime

        if (num % i == 0) {

            return false;

        }

    }

    // If no divisors were found, num is prime

    return true;

}

int main() {

    int num;

    cout << “Enter a number: “;

    cin >> num;

    // Check if the number is prime and output the result

    if (isPrime(num)) {

        cout << num << ” is a prime number.” << endl;

    } else {

        cout << num << ” is not a prime number.” << endl;

    }

    return 0;

}

 

Detailed Explanation

  • Function isPrime:

This function takes an integer num as input and returns true if num is prime; otherwise, it returns false. It first handles the base case—if num is less than 2, it returns false because prime numbers are greater than 1. Then, it checks for divisors of num from 2 up to the square root of num (inclusive). This range suffices due to the mathematical property that if num has a divisor greater than its square root, it must also have a divisor smaller than the square root, thereby ensuring all potential divisors are checked. If any divisor is found (indicated by num % i == 0), the function returns false.

  • Main Program:

In the main function, the user is prompted to enter a number. The program then calls isPrime to check if the entered number is prime and outputs the appropriate message based on the function’s return value.

C++ Program to Check Whether a Number is a Palindrome or Not

Palindrome is a sequence that reads the same backward as forward. Palindrome checking is a classic problem in computer science and programming education, illustrating basic concepts such as loops, conditionals, and the manipulation of numbers or strings. In the case of numeric palindromes, the problem typically involves reversing a number and comparing it to the original to determine if they are the same.

This task can be approached in various ways, but one straightforward method involves reversing the given number and then comparing the reversed number with the original number. If they are identical, the number is a palindrome.

C++ Program to Check Numeric Palindrome

Here is a simple C++ program that checks if a given integer is a palindrome. The program outlines the process of reversing a number and comparing the reversed number with the original.

#include <iostream>

using namespace std;

// Function to reverse a number

int reverseNumber(int num) {

    int reversed = 0;

    while(num > 0) {

        reversed = reversed * 10 + num % 10;

        num /= 10;

    }

    return reversed;

}

// Function to check if a number is a palindrome

bool isPalindrome(int num) {

    // Negative numbers are not considered palindromes

    if (num < 0) return false;

   

    // Compare original number with its reverse

    return num == reverseNumber(num);

}

int main() {

    int num;

    cout << “Enter a number: “;

    cin >> num;

   

    if (isPalindrome(num)) {

        cout << num << ” is a palindrome.” << endl;

    } else {

        cout << num << ” is not a palindrome.” << endl;

    }

   

    return 0;

}

 

Explanation

  • Reversing a Number:

The reverseNumber function reverses the digits of the given number. It initializes an integer reversed to 0 and iteratively extracts the last digit of num (using num % 10), appends it to reversed, and removes the last digit from num (using num /= 10) until num becomes 0.

  • Checking for Palindrome:

The isPalindrome function first handles a special case by returning false if the number is negative, as negative numbers are not considered palindromes due to the leading minus sign. It then calls reverseNumber to reverse the input number and compares the reversed number with the original. If they are the same, it returns true, indicating the number is a palindrome; otherwise, it returns false.

  • Main Program Flow:

The main function asks the user to enter a number, checks if it’s a palindrome by calling isPalindrome, and outputs the result.

C++ Program to Check Neon Numbers in a Given Range

A Neon number is an intriguing concept in the realm of mathematics and computer science. It is a number where the sum of the digits of its square equals the number itself. For instance, 9 is a neon number because 9^2 = 81, and the sum of the digits of 81 (8 + 1) equals 9.

Understanding Neon Numbers

To identify neon numbers, one must perform the following steps for each number in the given range:

  • Square the Number:

First, compute the square of the number.

  • Sum the Digits:

Next, calculate the sum of the digits of the squared number.

  • Compare with Original:

Finally, check if the sum of the digits equals the original number. If so, the number is a neon number.

This process involves fundamental operations like multiplication and digit extraction, the latter typically achieved through division and modulus operations.

Algorithm for Finding Neon Numbers in a Range

Before implementing the program, let’s outline the algorithm to find and display all neon numbers within a specified range:

  1. Input Range: Obtain the lower and upper bounds of the range from the user.
  2. Iterate Through the Range: For each number in the range, perform the following steps:
    • Square the number.
    • Calculate the sum of the digits of the square.
    • Check if the sum equals the original number.
    • If so, display the number as a neon number.
  3. Repeat until all numbers in the range have been checked.

Implementing the Program

Now, let’s translate the above algorithm into a C++ program:

#include <iostream>

using namespace std;

// Function to calculate the sum of digits of a number

int sumOfDigits(int n) {

    int sum = 0;

    while (n > 0) {

        sum += n % 10; // Add the rightmost digit to sum

        n /= 10;       // Remove the rightmost digit from n

    }

    return sum;

}

// Function to check if a number is a Neon Number

bool isNeon(int num) {

    int square = num * num; // Calculate square of num

    int sum = sumOfDigits(square); // Sum the digits of the square

    return sum == num; // Return true if sum of digits equals num

}

int main() {

    int lower, upper;

    // Prompt user for the range

    cout << “Enter the lower and upper bounds of the range: “;

    cin >> lower >> upper;

    cout << “Neon numbers between ” << lower << ” and ” << upper << ” are:” << endl;

    // Iterate through the range and check for Neon Numbers

    for (int i = lower; i <= upper; ++i) {

        if (isNeon(i)) {

            cout << i << ” “;

        }

    }

    return 0;

}

 

Program Explanation

  1. Sum of Digits Function (sumOfDigits):

This helper function takes an integer n and returns the sum of its digits. It does so by repeatedly extracting the rightmost digit (using n % 10), adding it to the sum, and then removing this digit from n (using n /= 10).

  1. Neon Number Checker Function (isNeon):

The isNeon function checks whether a given number is a neon number. It squares the number, uses sumOfDigits to calculate the sum of the digits of the square, and then checks if this sum equals the original number.

  1. Main Function:

After obtaining the range from the user, the program iterates through each number in this range, using the isNeon function to determine if it is a neon number. If a number is found to be neon, it is printed to the console.

C++ Program to Check Armstrong Number

An Armstrong number, also known as a narcissistic number, is an intriguing concept in number theory that finds practical applications in programming exercises, particularly those focusing on algorithm design, control structures, and number manipulation. An Armstrong number of a given number of digits is a number in which the sum of its own digits each raised to the power of the number of digits equals the number itself. For example, 153 is an Armstrong number because 5^3+3^3 = 153.

Understanding and implementing a program to check for Armstrong numbers not only helps in grasping basic programming concepts but also in appreciating the elegance of numerical properties. This exercise typically involves breaking down the problem into key steps: determining the number of digits, calculating the sum of the digits each raised to a certain power, and comparing this sum to the original number.

Breakdown of the Solution

  1. Determine the Number of Digits:

This involves a loop where you repeatedly divide the number by 10 until it becomes 0. The number of iterations gives you the number of digits.

  1. Calculate the Sum of Powers of the Digits:

Using the number of digits calculated in step 1, you raise each digit to this power and sum these values. This requires isolating each digit (using modulus and division operations) and then using the pow function from the <cmath> library to raise each digit to the power of the number of digits.

  1. Compare the Sum to the Original Number:

If the sum obtained in step 2 equals the original number, it is an Armstrong number.

Implementing the Program

Let’s now translate the solution into a C++ program:

#include <iostream>

#include <cmath> // For pow() function

using namespace std;

// Function to calculate the number of digits in the number

int countDigits(int n) {

    int count = 0;

    while (n != 0) {

        count++;

        n /= 10;

    }

    return count;

}

// Function to check if the given number is an Armstrong number

bool isArmstrong(int num) {

    int originalNum = num;

    int numOfDigits = countDigits(num);

    int sumOfPowers = 0;

    while (num != 0) {

        int digit = num % 10;

        sumOfPowers += pow(digit, numOfDigits);

        num /= 10;

    }

    return sumOfPowers == originalNum;

}

int main() {

    int num;

    // Prompt the user for input

    cout << “Enter a number: “;

    cin >> num;

    if (isArmstrong(num)) {

        cout << num << ” is an Armstrong number.” << endl;

    } else {

        cout << num << ” is not an Armstrong number.” << endl;

    }

    return 0;

}

 

Detailed Explanation

  1. Counting Digits (countDigits function):

This function takes an integer as input and returns the count of digits in that number. It does so by dividing the number by 10 in a loop until the number becomes 0, incrementing a counter at each step.

  1. Checking for Armstrong Number (isArmstrong function):

The isArmstrong function assesses whether a given number is an Armstrong number. It first stores the original number for later comparison. It then calculates the sum of each digit raised to the power equal to the number of digits in the number. This is accomplished by isolating each digit using modulus and division operations and raising it to the power calculated by the countDigits function.

  1. Main Logic:

The main function prompts the user for a number, uses the isArmstrong function to check if the number is an Armstrong number, and displays the result accordingly.

C++ Program to Calculate the Power of a Number

Calculating the power of a number involves multiplying the number by itself a certain number of times, indicated by the exponent. In C++, this operation can be performed using a simple loop, the std::pow function from the <cmath> library for a more straightforward approach, or even recursively for educational purposes.

Iterative Approach

An iterative approach to calculating the power of a number allows us to understand the basic principle behind exponentiation. It involves multiplying the base number by itself n-1 times, where n is the exponent.

#include <iostream>

using namespace std;

// Function to calculate power

long long power(int base, int exponent) {

    long long result = 1;

    for(int i = 0; i < exponent; i++) {

        result *= base;

    }

    return result;

}

int main() {

    int base, exponent;

    cout << “Enter the base: “;

    cin >> base;

    cout << “Enter the exponent: “;

    cin >> exponent;

    long long result = power(base, exponent);

    cout << base << ” raised to the power of ” << exponent << ” is ” << result << “.” << endl;

    return 0;

}

 

Using std::pow Function

For many applications, the std::pow function offers a more direct and possibly more efficient way to compute powers, especially when dealing with floating-point numbers. Here’s how you can use it:

#include <iostream>

#include <cmath> // Include for std::pow

int main() {

    double base;

    double exponent;

    cout << “Enter the base: “;

    cin >> base;

    cout << “Enter the exponent: “;

    cin >> exponent;

    double result = std::pow(base, exponent);

    cout << base << ” raised to the power of ” << exponent << ” is ” << result << “.” << endl;

    return 0;

}

 

Recursive Approach

For educational purposes, here’s how you might implement a simple recursive function to calculate powers. This method is not the most efficient but demonstrates the concept of recursion.

#include <iostream>

using namespace std;

// Recursive function to calculate power

long long power(int base, int exponent) {

    if (exponent == 0)

        return 1; // Base case: any number to the power of 0 is 1

    else

        return base * power(base, exponent – 1);

}

int main() {

    int base, exponent;

    cout << “Enter the base: “;

    cin >> base;

    cout << “Enter the exponent: “;

    cin >> exponent;

    long long result = power(base, exponent);

    cout << base << ” raised to the power of ” << exponent << ” is ” << result << “.” << endl;

    return 0;

}

Each of these approaches has its use cases:

  • The iterative approach gives you a solid understanding of how powers are calculated from the ground up.
  • The std::pow function is convenient and efficient, especially for floating-point arithmetic.
  • The recursive approach is educational, illustrating the concept of recursion but may not be as efficient due to the function call overhead and the risk of stack overflow for large exponents.
error: Content is protected !!