0% found this document useful (0 votes)
16 views3 pages

Computer Fundamentals and Programming

The document provides examples of C++ programs to print the sizes of fundamental data types, print the results of specified expressions, and swap two numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Computer Fundamentals and Programming

The document provides examples of C++ programs to print the sizes of fundamental data types, print the results of specified expressions, and swap two numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Republic of the Philippines

CAMARINES SUR POLYTECHNIC COLLEGES


Nabua, Camarines Sur
Tel. No. (054) 288-4421 to 23 (loc. 164)
Computer Fundamentals and Programming

1. Write a program in C++ to find size of fundamentals data types.


a. Find the size of fundamental data types
1byte, 2bytes,4bytes,8bytes using the data types of ( char,short,int,long,long
long)
#include <iostream>
using namespace std;

int main() {
cout << "Size of char: " << sizeof(char) << " bytes." << endl;
cout << "Size of short: " << sizeof(short) << " bytes." << endl;
cout << "Size of int: " << sizeof(int) << " bytes." << endl;
cout << "Size of long: " << sizeof(long) << " bytes." << endl;
cout << "Size of long long: " << sizeof(long long) << " bytes." << endl;

return 0;
}

2. Write a program in C++ to print the result of the specified operation.


Result of first expression is : 23
2nd : 5
3nd : 12
4th : 3

BERRR 1
Republic of the Philippines
CAMARINES SUR POLYTECHNIC COLLEGES
Nabua, Camarines Sur
Tel. No. (054) 288-4421 to 23 (loc. 164)
Computer Fundamentals and Programming

#include <iostream>
using namespace std;

int main() {
int num1 = 23, num2 = 5, num3 = 12, num4 = 3;

cout << "Result of first expression is : " << num1 << endl;
cout << "Result of second expression is : " << num2 << endl;
cout << "Result of third expression is : " << num3 << endl;
cout << "Result of fourth expression is : " << num4 << endl;

return 0;
}

3. Write a program in C++ to swap two numbers


1st number : 25
2nd number : 39

BERRR 2
Republic of the Philippines
CAMARINES SUR POLYTECHNIC COLLEGES
Nabua, Camarines Sur
Tel. No. (054) 288-4421 to 23 (loc. 164)
Computer Fundamentals and Programming

#include <iostream>
using namespace std;

int main() {
int num1 = 25, num2 = 39, temp;

cout << "Before swapping:" << endl;


cout << "First number: " << num1 << endl;
cout << "Second number: " << num2 << endl;

// swap the values of num1 and num2


temp = num1;
num1 = num2;
num2 = temp;

cout << "After swapping:" << endl;


cout << "First number: " << num1 << endl;
cout << "Second number: " << num2 << endl;

return 0;
}

BERRR 3

You might also like