Assignment Solutions - Variables and Data Types
Assignment Solutions - Variables and Data Types
Assignment Solutions
Assignment Solutions
Q1 - Take 2 integer values in two variables x and y and print their product.
#include <iostream>
int main()
int x = 23;
int y = 50;
return 0;
#include <iostream>
int main()
return 0;
Q3 - Write a C++ program to take length and breadth of a rectangle and print its area.
#include <iostream>
int main()
int length=10;
int breadth=20;
return 0;
#include <iostream>
int main()
int x = 2;
int cube;
return 0;
#include <iostream>
int main()
cout << " The sizeof(char) : " << sizeof(char) << " bytes \n" ;
cout << " The sizeof(short) : " << sizeof(short) << " bytes \n" ;
cout << " The sizeof(int) : " << sizeof(int) << " bytes \n" ;
cout << " The sizeof(long): " << sizeof(long) << " bytes \n" ;
cout << " The sizeof(long long) :" << sizeof(long long) << " bytes \n";
cout << " The sizeof(float) :" << sizeof(float) << " bytes \n" ;
cout << " The sizeof(double) :" << sizeof(double) << " bytes \n";
cout << " The sizeof(long double) :" << sizeof(long double) << " bytes \n";
cout << " The sizeof(bool) : " << sizeof(bool) << " bytes \n\n";
return 0;
Q6 - Write a C++ program to swap two numbers with the help of a third variable.
#include <iostream>
int main()
int n1 = 2, n2 = 5, temp;
cout << " Before swapping the 1st number is : "<< n1 <<"\n" ;
cout << " Before swapping the 2nd number is : "<< n2 <<"\n" ;
temp=n2;
n2=n1;
n1=temp;
cout << " After swapping the 1st number is : "<< n1 <<"\n" ;
cout << " After swapping the 2nd number is : "<< n2 <<"\n" ;