cpp-advanced
cpp-advanced
int main() {
int i = 1;
start:
cout << i << " ";
i++;
if (i <= 10) {
goto start; // jumps to the start label
}
int main() {
cout << "Printing odd numbers between 1 and 10:" << endl;
// 33. Create a single dimensional array read 10 numbers and print the same
#include <iostream>
using namespace std;
int main() {
int numbers[10];
// Read 10 numbers
for (int i = 0; i < 10; i++) {
cout << "Enter number " << (i+1) << ": ";
cin >> numbers[i];
}
int main() {
int rows = 3;
int cols = 3;
int matrix[3][3];
int rowSum[3] = {0};
int colSum[3] = {0};
// Display matrix
cout << "Matrix:" << endl;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
cout << matrix[i][j] << "\t";
}
cout << endl;
}
return 0;
}
int main() {
int size = 5;
int numbers[5];
int squares[5];
// Read numbers
for (int i = 0; i < size; i++) {
cout << "Enter number " << (i+1) << ": ";
cin >> numbers[i];
// Calculate square
squares[i] = numbers[i] * numbers[i];
}
return 0;
}
int main() {
int size = 5;
int numbers[5];
int sum = 0;
cout << "The sum of the array elements is: " << sum << endl;
return 0;
}
int main() {
int a[3][3], b[3][3], result[3][3];
// Multiply matrices
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
result[i][j] += a[i][k] * b[k][j];
}
}
}
return 0;
}
// Function declaration
void greet();
int main() {
// Function call
greet();
return 0;
}
// Function definition
void greet() {
cout << "Hello from a simple function!" << endl;
}
// 39. Function with parameter
#include <iostream>
using namespace std;
// Function declaration
void greetPerson(string name);
int main() {
string userName;
return 0;
}
// Function definition
void greetPerson(string name) {
cout << "Hello, " << name << "! Welcome to C++ Programming." << endl;
}
// Function declaration
int add(int a, int b);
int main() {
int num1, num2;
return 0;
}