0% found this document useful (0 votes)
10 views

ALL C++ Program

Uploaded by

ambikagautam9118
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)
10 views

ALL C++ Program

Uploaded by

ambikagautam9118
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/ 5

ALL C++ PROGRAM AND SOLUTIONS

First program
#include <iostream>
using namespace std;

int main() {
cout << "Hello World!";
cout << "Hello World! \n";
cout << "Hello World!"<< "\n";
cout << "Hello World!"<< "\n\n";
return 0;
}

USER INPUT
#include <iostream>
using namespace std ;
int main ()
{
int x;
cout << "Type a number: "; // Type a number and press enter
cin >> x; // Get user input from the keyboard
cout << "Your number is: " << x; // Display the input value
return 0;

}
BOOLEAN
#include<iostream>
using namespace std;
int main()
{
bool CodingisFun = true;
bool cakeisTasty = false;
cout << CodingisFun<< "\n"; // Outputs 1 (true)
cout << cakeisTasty;
return 0;
}
AREA OF RECTANGLE
#include <iostream>
using namespace std;
int main()
{
// Create integer variables
int length = 12;
int width = 10;
int area;
// Calculate the area of a rectangle
area = length * width;
// Print the variables
cout << "Length is: " << length << "\n";
cout << "Width is: " << width << "\n";
cout << "Area of the rectangle is: " << area << "\n";
return 0;
}
CREATE VARIABLE
#include <iostream>
using namespace std;
int main() {
int myNum;
myNum = 15;
cout << myNum;
return 0;
}
DECLARE VARIABLE
#include <iostream>
using namespace std;
int main() {
//assign the same value to multiple variables in one line//
int x, y, z;
x = y = z = 50;
cout << x + y + z;
return 0;
}
DIFFERENT DATA TYPE
#include <iostream>
using namespace std;
int main() {
// Create variables of different data types
int items = 50;
double cost_per_item = 9.99;
double total_cost = items * cost_per_item;
char currency = '$';
// Print variables
cout << "Number of items: " << items << "\n";
cout << "Cost per item: " << cost_per_item << "" << currency << "\n";
cout << "Total cost = " << total_cost << "" << currency << "\n";
return 0;
}
DISPLAY VARIABLE
#include <iostream>
using namespace std;
int main() {
int myAge = 35;
cout << "I am " << myAge << " years old.";
return 0;
}
IDENTIFIERS
#include <iostream>
using namespace std;
int main() {
//identifiers
/*int minutesPerHour = 60;
int m = 60;*/
//constants
int myNum = 15; // Now myNum is 15
myNum = 10; // Now myNum is 10
cout << myNum;
//const int minutesPerHour = 60;
return 0;
}
REVERSE NUMBER
#include <iostream>
using namespace std;
int main() {
// A variable with some specific numbers
int numbers = 12345;
// A variable to store the reversed number
int revNumbers = 0;
// Reverse and reorder the numbers
while (numbers) {
// Get the last number of 'numbers' and add it to 'revNumbers'
revNumbers = revNumbers * 10 + numbers % 10;
// Remove the last number of 'numbers'
numbers /= 10;
}
cout << "Reversed numbers: " << revNumbers << "\n";
return 0;
}

You might also like