---
# System prepended metadata

title: 'Search code python,c++,pascal'

---

# Search code python,c++,pascal
## Program structure- Hello World
### Python
``` python=
print("Hello World")
```
### C++
``` cpp=
#include<iostream>
using namespace std;

int main(){
    cout << "Hello World" << endl;
}
```
### Pascal
``` pascal=
begin
    writeln('Hello world');
end.
```
## Data types and variables
### Python
``` python=
a = 1
b = 1.5
s = "Ucode.vn"

print(a,b,s)
```
### C++
``` cpp=
#include<iostream>
using namespace std;

int main(){
    int a=1;
    double b=1.5;
    string s="Ucode.vn";

    cout << a << endl << b << endl << s;
}
```
### Pascal
``` pascal=
var a : integer=1;
    b : double =1.5;
    s : string ="Ucode.vn";
begin
    writeln(a);
    writeln(b);
    writeln(s);
end.
```
## Arithmetic Operations and Math Functions
### Python
``` python=
from math import*#(For Math Functions)
a = 10
b = 3

# Arithmetic Operations
sum = a+b #--> 10+3= 13
minus = a-b #--> 10-3= 7
multiply = a*b #--> 10*3= 30
divide1 = a/b #--> 10/3= 3.333333333
divide2 = a//b # --> 10//3= 3
remainder = a%b #--> 10%3= 1
power = a**b #--> 10**3=1000

print(sum,minus,multiply,divide1,divide2,remainder)

#Math functions
absolute_value=abs(-3)#-->fabs(-3)= |-3|= 3
floor = floor(8.6)#--> floor(8.6)= 8 (The biggest integer<8.6)
ceil = ceil(8.6)#--> ceil(8.6)= 9 (The smallest integer>8.6)
square_root=sqrt(9)#--> sqrt(9)= √9= 3.0 (float)

print(absolute_value,floor,ceil,square_root,power)
```
### C++
``` cpp=
#include<iostream>
#include<cmath>//(For Math Functions)
using namespace std;

int main(){
    int a = 10;
    int b = 3;
    
    // Arithmetic Operations
    int sum = a+b; //--> 10+3= 13
    int minus = a-b; //--> 10-3= 7
    int multiply = a*b; //--> 10*3= 30
    double divide1 = (double)a/(double)b; //--> 10/3= 3.333333333
    int divide2 = (int)a/(int)b; // --> 10/3= 3
    int remainder = a%b; //--> 10%3= 1
    
    cout << sum << " " << minus << " " << multiply <<" "<<divide1<<" " 
         << divide2 << " " << remainder;
    
    //Math functions
    int absolute_value=abs(-3);//-->fabs(-3)= |-3|= 3
    //--> floor(8.6)= 8 (The biggest integer<8.6)
    //--> ceil(8.6)= 9 (The smallest integer>8.6)
    double square_root=sqrt(9);//--> sqrt(9)= √9= 3.0 (double)
    double power = pow(2,3);//--> pow(2,3)= 2^3= 8.0 (double)
    
    cout << absolute_value << " " << floor(8.6) << " " << ceil(8.6) << " " 
         << square_root << " " << power;
}
```
### Pascal
``` pascal=
var a,b,sum,minus,multiply,divide2,remainder,absolute_value,trunc,round,           square_root : integer;
var divide1:double;
begin
    a := 10;
    b := 3;

    // Arithmetic Operations
    sum := a+b; //--> 10+3= 13
    minus := a-b; //--> 10-3= 7
    multiply := a*b; //--> 10*3= 30
    divide1 := a/b; //--> 10/3= 3.333333333
    divide2 := a div b; // --> 10 div 3= 3
    remainder := a mod b; // --> 10 mod 3= 1

    // Math functions
    absolute_value:=ABS(-3);//-->ABS(-3)= |-3|= 3
    trunc := TRUNC(8.6);//--> TRUNC(8.6)= 8 (The biggest integer<8.6)
    round := ROUND(8.6);//--> ROUND(8.6)= 9 (The smallest integer>8.6)
    square_root:=SQRT(9);#--> SQRT(9)= √9= 3

    writeln(sum,minus,multiply,divide1,divide2,remainder);
    writeln(absolute_value,trunc,round,square_root);
end.
```
## Data Input/Output
### Python
```python=
#Input
a = int(input())#input an integer
b = str(input())#input a string
c = float(input())#input a float
##input a list
### First way
n = int(input()#number of elements
s = []
for i in range(n):
    s.append(int(input()))
### Second way
n = int(input()#number of elements
s = [0]*n
for i in range(n):
    s[i]=int(input())
#Output
print(a,b,s)# basic output 
print(round(c,d))#round the float c for d digits after the dot
```

### C++
``` cpp=
#include<iostream>
#include<iomanip> //setprecision,fixed
#include<vector> // vector
using namespace std;

int main(){
    int a;
    string s;
    vector<int> inte;//a vector of integer
    vector<double> dble;//a vector of double
    //Input
    cin >> a;//basic input
    cin >> s;//input a string with no space
    getline(cin,s);//input a string with space
    ///Input a Vector
    int n;cin >> n;//number of elements in vector
    for(int i=0;i<n;i++){
        cin >> a;
        inte.push_back(a);
    }
    //Output
    cout << a << " " << s; //basic output
    cout << fixed << setprecision(n) << b;//round the double b for n digits                                             after the dot
    for(size_t i=0;i<inte.size();i++){
        cout << inte[i] << " ";
    }// vector output
}
```
### Pascal
```
var a,b,c:integer;var f:double; var s:string;
var inte : array[1..20] of integer; // an array with maximum 20 integer                                            elements
var n:integer; inte has n elements
var i:integer; //(for loops)
begin
    //Input
    readln(a,s);
    /// Input an array
    for i:=0 to n do
    begin
        readln(inte[i]);
    end;
    //Output
    writeln(a,s);
    writeln(f:0:8);//output a real number to 8 digits after the dots
    //Output an array
    begin
    for i :=0 to n do
        writeln(inte[i]);
    end;
end.
```
## Data Conversion
### Python
```python=
a = 100
int(a,2)# convert a to base 2
a = str(a) # change a to string
a = tuple(a) # change a to tuple
# (type)(variables)--> change type of variables
# for all types

```

### C++
``` cpp=
#include<iostream>
using namespace std;

int main(){
    double x=1.2;
    //Implicit convert
    int a = x+1;
    //Excilcit convert
    int b = (int)x + 1;
    /// (type)variables--> change type of variables
}
```
### Pascal
```
    
```
## Conditional statements
### Python
```python=
a = int(input())
if(a==100):
    print(a)
elif(a<100):
    print(a-1)
else:
    print(a+1)

```

### C++
``` cpp=
#include<iostream>
using namespace std;

int main(){
    int a;
    cin >> a;
    if(a==100) cout << a;
    else if(a<100) cout << a-1;
    else cout << a+1;
    //Switch
}
```
### Pascal
```
    
```
