C Online Compiler
Example: Cube of a Number (Conditional) in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Cube of a Number (Conditional) #include <stdio.h> int main() { int number; long long cube; // Use long long for cube to handle larger results // Step 1: Prompt the user to enter an integer printf("Enter an integer: "); // Step 2: Read the integer from the user scanf("%d", &number); // Step 3: Check if the number is NOT divisible by 2 AND NOT divisible by 3 if ((number % 2 != 0) && (number % 3 != 0)) { // Step 4: If the condition is met, calculate the cube cube = (long long)number * number * number; printf("The number %d is not divisible by 2 and not divisible by 3.\n", number); printf("The cube of %d is: %lld\n", number, cube); } else { // Step 5: If the condition is not met, print an appropriate message printf("The number %d is divisible by 2 or 3 (or both). Cannot compute its cube under the given condition.\n", number); } return 0; }
Output
Clear
ADVERTISEMENTS