0% found this document useful (0 votes)
13 views5 pages

Question 1 PDF

The document contains multiple C++ code snippets demonstrating various programming concepts. It includes examples of generating multiplication tables, implementing a stack data structure, using a queue, counting the number of digits in an integer, and checking if the product of the digits equals their sum. Each code snippet is self-contained and showcases basic input/output operations and control structures.

Uploaded by

gargeekanwa1121
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Question 1 PDF

The document contains multiple C++ code snippets demonstrating various programming concepts. It includes examples of generating multiplication tables, implementing a stack data structure, using a queue, counting the number of digits in an integer, and checking if the product of the digits equals their sum. Each code snippet is self-contained and showcases basic input/output operations and control structures.

Uploaded by

gargeekanwa1121
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Question 1:

#include <iostream>

using namespace std;

int main() {

int num = 2;

do {

cout << "Table of " << num << ":" << endl;

int i = 1;

do {

cout << num << " * " << i << " = " << num * i << endl;

i++;

} while (i <= 10);

cout << endl;

num++;

} while (num <= 10);

return 0;

Question: 2

#include <iostream>

using namespace std;

class Stack {

private:

int arr[5];

int top;
public:

Stack() {

top = -1;

void push(int value) {

if (top == 4) {

cout << "Stack Overflow!" << endl;

return;

arr[++top] = value;

int pop() {

if (top == -1) {

cout << "Stack Underflow!" << endl;

return -1;

return arr[top--];

int peek() {

if (top == -1) {

cout << "Stack is empty!" << endl;

return -1;

return arr[top];
}

bool isEmpty() {

return top == -1;

bool isFull() {

return top == 4;

};

int main() {

Stack s;

s.push(1);

s.push(2);

s.push(3);

cout << "Top element: " << s.peek() << endl;

cout << "Popped element: " << s.pop() << endl;

cout << "Is stack empty? " << s.isEmpty() << endl;

cout << "Is stack full? " << s.isFull() << endl;

return 0;

Question 3:

#include <iostream>

#include <queue>
using namespace std;

int main() {

queue<int> q;

q.push(1);

q.push(2);

q.push(3);

cout << q.front() << endl; // Output: 1

q.pop();

cout << q.front() << endl; // Output: 2

return 0;

Question 4:

#include <iostream>

using namespace std;

int main() {

int n;

cout << "Enter an integer: ";

cin >> n;

int count = 0;

n = abs(n);

do {

n /= 10;
count++;

} while (n != 0);

cout << "Number of digits: " << count << endl;

return 0;

Question:5

#include <iostream>

using namespace std;

int main() {

int n = 123, product = 1, sum = 0;

while (n) {

int digit = n % 10;

product *= digit;

sum += digit;

n /= 10;

cout << (product == sum) << endl;

return 0;

You might also like