0% found this document useful (0 votes)
9 views10 pages

Lab1 2

The document contains multiple C++ programs that perform various tasks such as printing a sentence, taking user input for integers, calculating the sum of two numbers, finding ASCII values, computing quotient and remainder, multiplying floating-point numbers, swapping two numbers, and checking if a number is even or odd.

Uploaded by

toptoonsbd
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)
9 views10 pages

Lab1 2

The document contains multiple C++ programs that perform various tasks such as printing a sentence, taking user input for integers, calculating the sum of two numbers, finding ASCII values, computing quotient and remainder, multiplying floating-point numbers, swapping two numbers, and checking if a number is even or odd.

Uploaded by

toptoonsbd
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

Problem 1

/ program to print a sentence

#include <iostream>

using namespace std;

int main() {

cout << "Hello world." << endl;

return 0;

}
//program to find a integer entered by user

#include <iostream>

using namespace std;

int main() {

int num;

cout << "Enter a number: ";

cin >> num;

cout << "You entered: " << num << endl;

return 0;

}
Problem 3

#include <iostream>

using namespace std;

int main() {

int a, b;

cout << "Enter number 1: ";

cin >> a ;

cout << "Enter number 2: ";

cin >> b;

cout << "Sum: " << a + b << endl;

return 0;

}
// program to find ascii value

#include <iostream>

using namespace std;

int main() {

char c;

cout << "Enter a character: ";

cin >> c;

cout << "ASCII Value of " << c << " is " << (int)c << endl;

return 0;

}
// program t find quotient value and reminder

#include <iostream>

using namespace std;

int main() {

int dividend, divisor;

cout << "Enter dividend : ";

cin >> dividend ;

cout << "Enter divisor: ";

cin >> divisor;

cout << "Quotient: " << dividend / divisor << endl;

cout << "Remainder: " << dividend % divisor << endl;

return 0;

//program to multiply two floating numbers

#include <iostream>

using namespace std;

int main() {

double x, y;

cout << "Enter number1: ";

cin >> x ; cout << "Enter two number2: ";

cin >> y;

cout << "Product: " << x * y << endl;


return 0;

}
//program to multiply two floating numbers

#include <iostream>

using namespace std;

int main() {

double x, y;

cout << "Enter number1: ";

cin >> x ; cout << "Enter two number2: ";

cin >> y;

cout << "Product: " << x * y << endl;

return 0;}
// program t find quotient value and reminder

#include <iostream>

using namespace std;

int main() {

int dividend, divisor;

cout << "Enter dividend : ";

cin >> dividend ;

cout << "Enter divisor: ";

cin >> divisor;

cout << "Quotient: " << dividend / divisor << endl;

cout << "Remainder: " << dividend % divisor << endl;

return 0;

}
// program to swap numbers

#include <iostream>

using namespace std;

int main() {

int a, b, temp;

cout << "Enter a and b: ";

cin >> a >> b;

temp = a;

a = b;

b = temp;

cout << "After swapping: a = " << a << ", b = " << b << endl;

return 0;

}
// program to check even or odd

#include <iostream>

using namespace std;

int main() {

int n;

cout << "Enter a number: ";

cin >> n;

if (n % 2 == 0) cout << "Even";

else cout << "Odd";

return 0;

You might also like