Assignment CFP

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Cedrick Vincent A.

Tapalla

BSCE 1A

ASSIGNMENT IN CFP

 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)

Program:

1. #include <iostream>
2.
3. using namespace std;
4.
5. int main()
6. {
7. cout << “\n\n Find Size of fundamental data types :\n”;
8. cout << “------------------------------------------\n”;
9. cout << “ The sizeof(char) is : “ << sizeof(char) << “ bytes \n” ;
10. cout << “ The sizeof(short) is : “ << sizeof(short) << “ bytes \n” ;
11. cout << “ The sizeof(int) is : “ << sizeof(int) << “ bytes \n” ;
12. cout << “ The sizeof(long) is : “ << sizeof(long) << “ bytes \n” ;
13. cout << “ The sizeof(long long) is : “ << sizeof(long long) << “ bytes \n”;
14. cout << “ The sizeof(float) is : “ << sizeof(float) << “ bytes \n” ;
15. cout << “ The sizeof(double) is : “ << sizeof(double) << “ bytes \n”;
16. cout << “ The sizeof(long double) is : “ << sizeof(long double) << “ bytes \n”;
17. cout << “ The sizeof(bool) is : “ << sizeof(bool) << “ bytes \n\n”;
18.
19. retrun 0;
20. }

 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

Program:

1. #include <iostream>
2.
3. Using namespace std;
4.
5. Int main()
6. {
7. Cout << “\n\n Print the result of some specific operation :\n”;
8. Cout << “--------------------------------------------------\n”;
9.
10. Cout << “ Result of 1st expression is : “<< (-1+4*6) <<”\n” ;
11. Cout << “ Result of 2nd expression is : “<< ((35+5)%7) <<”\n” ;
12. Cout << “ Result of 3rd expression is : “<< (14+-4*6/11) <<”\n” ;
13. Cout << “ Result of 4th expression is : “<< (2+15/6*1-7%2) <<”\n\n” ;
14.
15. Return 0;
16. }

 Write a program in C++ to swap two numbers


1st number : 25
2nd number : 39

Program:

1. #include <iostream>
2.
3. Using namespace std;
4.
5. Int main()
6. {
7. Cout << “\n\n Swap two numbers :\n”;
8. Cout << “-----------------------\n”;
9.
10. Int num1, num2, temp;
11. Cout << “ Input 1st number : “;
12. Cin >> num1 ;
13.
14. Cout << “ Input 2nd number : “;
15. Cin >> num2;
16.
17. Temp = num2;
18. Num2 = num1;
19. Num1 = temp;
20.
21. Cout << “ After swapping the 1st number is : “<< num1 <<”\n” ;
22. Cout << “ After swapping the 2nd number is : “<< num2 <<”\n\n” ;
23.
24. Return 0;
25. }
26.
27.

You might also like