computer assignment 2
computer assignment 2
This program uses a switch statement and appropriate formulas to compute volumes of a cube,
cylinder, or sphere based on user choice.
#include <iostream>
int main() {
int choice;
do {
switch (choice) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
return 0;
}
Print All Prime Numbers Between 1 and 300
This uses a for loop and nested loops to check for prime numbers:
#include <iostream>
int main() {
bool isPrime;
isPrime = true;
if (num % i == 0) {
isPrime = false;
break;
if (isPrime)
return 0;
}
Difference Between continue and break Statements
Demonstration:
#include <iostream>
int main() {
if (i == 5)
if (i == 5)
return 0;
Output:
1 2 3 4 1 2 3 4 5 6 7 8 9 10