c++ code to python code converter online
cout("HJello")
c++ code to python code converter online
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int num {};
vector <long double> list {};
long double sum {};
long double num_to_add {};
cout << "How many numbers do you want to add : ";
cin >> num;
for ( int i {1} ; i <= num ; ++i )
{
cout << "Enter the number " << i << " : ";
cin >> num_to_add;
list.push_back(num_to_add);
}
for (int i {} ; i < num ; ++i)
sum += list[i];
cout << "\nTheir sum is : " << sum << endl;
list.clear();
return 0;
}
c++ code to python code converter online
void decrypt(string &text, string &key){
for(size_t i=0;i<text.length()-1;i++){
for (int j=0;j<26;j++){
if (text[i]==key[j]){
text[i]=j+97;
break;
}
}
}
}
c++ code to python code converter online
#include <bits/stdc++.h>
using namespace std;
vector<int>bfs(vector<int>*adj,int src,int k)
{
if(k == 0)
{
vector<int>ans;
ans.push_back(src);
return ans;
}
map<int,bool>visited;
map<int,int>level;
vector<int>ans;
queue<int>inserter;
inserter.push(src);
level[src] = 0;
while(!inserter.empty())
{
int z = inserter.front();
visited[z] = true;
inserter.pop();
for(int i = 0 ; i < adj[z].size(); i++)
{
if(!visited[adj[z][i]])
{
visited[adj[z][i]] = true;
inserter.push(adj[z][i]);
level[adj[z][i]] = level[z] + 1;
if(level[adj[z][i]] == k)
ans.push_back(adj[z][i]);
if(level[adj[z][i]] > k)
break;
}
}
}
return ans;
}
void solve()
{
int target,m,n,sz;
vector<int>*adj;
cin>>sz;
adj = new vector<int>[sz + 1];
for(int i = 0 ; i < sz-1; i++)
{
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
cin>>target>>m;
vector<int>res = bfs(adj,target,m);
int x = res[0];
for(int i = 1 ; i < res.size(); i++)
{
x ^= res[i];
}
cout<<x<<endl;
}
int main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
c++ code to python code converter online
//*****************************************//
//Main function
//Kristine Joy Barroso//
//BSIT 2A
//*****************************************//
#include <iostream>
using namespace std;
//Function (1)
int max_range(int side1, int side2)
{
int range;
range= side1 + side2 - 1;
return(range);
}
//Function (2)
int product(int Minutes, int Seconds)
{
int result;
result = Minutes * Seconds;
return (result);
}
//Function(3)
long long convertDecimalToBinary(int n)
{
long long binaryNumber = 0;
int remainder, i = 1, step = 1;
while (n!=0)
{
remainder = n%2;
cout << "Step " << step++ << ": " << n << "/2, Remainder = " << remainder << ", Quotient = " << n/2 << endl;
n /= 2;
binaryNumber += remainder*i;
i *= 10;
}
return binaryNumber;
}
//Main function
int main()
{
int function;
jump:
cout<<"\nChoose Function number from (1-4): "
"\n(1)Finds Triangle's Third Angle."
"\n(2)Converts Minutes to Seconds."
"\n(3)Converts Decimal to Binary"
"\n(4)End Program\n"<<endl;
cin>>function;
switch(function)
{
case 1:
{
int range;
int side1, side2;
cout<<"Enter Side1: "<<endl;
cin>>side1;
cout<<"Enter Side 2: "<<endl;
cin>>side2;
range=max_range(side1,side2);
cout<<"the maximum range is "<<range<<endl;
goto jump;
}
case 2:
{
int Minutes;
int Seconds;
int result;
Seconds = 60;
cout<<"Enter Minutes to be converted to seconds: "<<endl;
cin>>Minutes;
result= product(Minutes, Seconds);
cout<<"the result is "<<result<<endl;
goto jump;
}
case 3:
{
int n, binaryNumber;
cout << "Enter a decimal number(0 - 255 only): ";
cin >> n;
binaryNumber = convertDecimalToBinary(n);
cout << n << " in decimal = " << binaryNumber << " in binary" << endl ;
goto jump;
}
case 4:
{
cout<<"PROGRAM END"<<endl;
return 0;
}
}
}
c++ code to python code converter online
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
struct n{
int d;
struct n*next;
};
void push(struct n**headref, int new_d)
{
struct n* new_node=new n;
new_node->d=new_d;
new_node->next=(*headref);
(*headref)=new_node;
}
float avgofnodes(struct n*head)
{
if(!head){return -1;}
int c=0;
int s=0;
float avg =0.0;
struct n*now=head;
while(now!=NULL)
{
c++;
s+=now->d;
now=now->next;
}
avg=(double)s/c;
return avg;
}
int main()
{
struct n*head=NULL;
push(&head , 7);
push(&head, 6);
push(&head, 8);
push(&head, 4);
push(&head, 1);
cout<<"Average of nodes = "<<avgofnodes(head);
return 0;
}
c++ code to python code converter online
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,n, sign = 1;
double det = 1; double temp;
double a[10][10],b[10][10];
// Nhap cap cua ma tran:
printf("\nCap cua ma tran vuon, n = "); scanf("%d",&n);
c++ code to python code converter online
#include <iostream>
using namespace std;
int main()
{
int a = 5, b = 10, temp;
cout << "Before swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
temp = a;
a = b;
b = temp;
cout << "\nAfter swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
return 0;
}
c++ code to python code converter online
#include<iostream>
#include<math.h>
#define vL 0.4
using namespace std;
struct generator
{
float IL,theat,Pout;
};
typedef struct generator GENERATOR;
int main()
{
int i=0,n;
float sum=0,avg,low,high,il,theat;
cout<<"Enter the value for 'n' : ";
cin>>n;
GENERATOR g[n];
while(i<n)
{
cout<<"Enter Voltage and Current";
cin>>il>>theat;
if(il>0&&theat>=35&&theat<=45){
g[i].IL=il;
g[i].theat=theat;
g[i].Pout=sqrt(3)*il*cos(theat);
cout<<g[i].Pout;
if(i==0)
{
low=g[i].Pout;
high=g[i].Pout;
}
++i;
}else
cout<<"\nEnter Valid data(il>0 and theat>=-35 and theat<=45)";
}
i=1;
while(i<n)
{
if(low>g[i].Pout)
low=g[i].Pout;
if(high<g[i].Pout)
high=g[i].Pout;
sum+=g[i].Pout;
i++;
}
avg=sum/n;
cout<<"\nThe Lowest Output Power :"<<low;
cout<<"\nThe highest Output Power :"<<high;
cout<<"\nThe Average Output Power :"<<avg;
}
OUTPUT
c++ code to python code converter online
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int num {};
vector <long double> list {};
long double sum {};
long double num_to_add {};
cout << "How many numbers do you want to add : ";
cin >> num;
for ( int i {1} ; i <= num ; ++i )
{
cout << "Enter the number " << i << " : ";
cin >> num_to_add;
list.push_back(num_to_add);
}
for (int i {} ; i < num ; ++i)
sum += list[i];
cout << "\nTheir sum is : " << sum << endl;
list.clear();
return 0;
}
c++ code to python code converter online
void decrypt(string &text, string &key){
for(size_t i=0;i<text.length()-1;i++){
for (int j=0;j<26;j++){
if (text[i]==key[j]){
text[i]=j+97;
break;
}
}
}
}
c++ code to python code converter online
#include <bits/stdc++.h>
using namespace std;
vector<int>bfs(vector<int>*adj,int src,int k)
{
if(k == 0)
{
vector<int>ans;
ans.push_back(src);
return ans;
}
map<int,bool>visited;
map<int,int>level;
vector<int>ans;
queue<int>inserter;
inserter.push(src);
level[src] = 0;
while(!inserter.empty())
{
int z = inserter.front();
visited[z] = true;
inserter.pop();
for(int i = 0 ; i < adj[z].size(); i++)
{
if(!visited[adj[z][i]])
{
visited[adj[z][i]] = true;
inserter.push(adj[z][i]);
level[adj[z][i]] = level[z] + 1;
if(level[adj[z][i]] == k)
ans.push_back(adj[z][i]);
if(level[adj[z][i]] > k)
break;
}
}
}
return ans;
}
void solve()
{
int target,m,n,sz;
vector<int>*adj;
cin>>sz;
adj = new vector<int>[sz + 1];
for(int i = 0 ; i < sz-1; i++)
{
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
cin>>target>>m;
vector<int>res = bfs(adj,target,m);
int x = res[0];
for(int i = 1 ; i < res.size(); i++)
{
x ^= res[i];
}
cout<<x<<endl;
}
int main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
c++ code to python code converter online
//*****************************************//
//Main function
//Kristine Joy Barroso//
//BSIT 2A
//*****************************************//
#include <iostream>
using namespace std;
//Function (1)
int max_range(int side1, int side2)
{
int range;
range= side1 + side2 - 1;
return(range);
}
//Function (2)
int product(int Minutes, int Seconds)
{
int result;
result = Minutes * Seconds;
return (result);
}
//Function(3)
long long convertDecimalToBinary(int n)
{
long long binaryNumber = 0;
int remainder, i = 1, step = 1;
while (n!=0)
{
remainder = n%2;
cout << "Step " << step++ << ": " << n << "/2, Remainder = " << remainder << ", Quotient = " << n/2 << endl;
n /= 2;
binaryNumber += remainder*i;
i *= 10;
}
return binaryNumber;
}
//Main function
int main()
{
int function;
jump:
cout<<"\nChoose Function number from (1-4): "
"\n(1)Finds Triangle's Third Angle."
"\n(2)Converts Minutes to Seconds."
"\n(3)Converts Decimal to Binary"
"\n(4)End Program\n"<<endl;
cin>>function;
switch(function)
{
case 1:
{
int range;
int side1, side2;
cout<<"Enter Side1: "<<endl;
cin>>side1;
cout<<"Enter Side 2: "<<endl;
cin>>side2;
range=max_range(side1,side2);
cout<<"the maximum range is "<<range<<endl;
goto jump;
}
case 2:
{
int Minutes;
int Seconds;
int result;
Seconds = 60;
cout<<"Enter Minutes to be converted to seconds: "<<endl;
cin>>Minutes;
result= product(Minutes, Seconds);
cout<<"the result is "<<result<<endl;
goto jump;
}
case 3:
{
int n, binaryNumber;
cout << "Enter a decimal number(0 - 255 only): ";
cin >> n;
binaryNumber = convertDecimalToBinary(n);
cout << n << " in decimal = " << binaryNumber << " in binary" << endl ;
goto jump;
}
case 4:
{
cout<<"PROGRAM END"<<endl;
return 0;
}
}
}
c++ code to python code converter online
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
struct n{
int d;
struct n*next;
};
void push(struct n**headref, int new_d)
{
struct n* new_node=new n;
new_node->d=new_d;
new_node->next=(*headref);
(*headref)=new_node;
}
float avgofnodes(struct n*head)
{
if(!head){return -1;}
int c=0;
int s=0;
float avg =0.0;
struct n*now=head;
while(now!=NULL)
{
c++;
s+=now->d;
now=now->next;
}
avg=(double)s/c;
return avg;
}
int main()
{
struct n*head=NULL;
push(&head , 7);
push(&head, 6);
push(&head, 8);
push(&head, 4);
push(&head, 1);
cout<<"Average of nodes = "<<avgofnodes(head);
return 0;
}
c++ code to python code converter online
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,n, sign = 1;
double det = 1; double temp;
double a[10][10],b[10][10];
// Nhap cap cua ma tran:
printf("\nCap cua ma tran vuon, n = "); scanf("%d",&n);
c++ code to python code converter online
#include <iostream>
using namespace std;
int main()
{
int a = 5, b = 10, temp;
cout << "Before swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
temp = a;
a = b;
b = temp;
cout << "\nAfter swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
return 0;
}
c++ code to python code converter online
#include<iostream>
#include<math.h>
#define vL 0.4
using namespace std;
struct generator
{
float IL,theat,Pout;
};
typedef struct generator GENERATOR;
int main()
{
int i=0,n;
float sum=0,avg,low,high,il,theat;
cout<<"Enter the value for 'n' : ";
cin>>n;
GENERATOR g[n];
while(i<n)
{
cout<<"Enter Voltage and Current";
cin>>il>>theat;
if(il>0&&theat>=35&&theat<=45){
g[i].IL=il;
g[i].theat=theat;
g[i].Pout=sqrt(3)*il*cos(theat);
cout<<g[i].Pout;
if(i==0)
{
low=g[i].Pout;
high=g[i].Pout;
}
++i;
}else
cout<<"\nEnter Valid data(il>0 and theat>=-35 and theat<=45)";
}
i=1;
while(i<n)
{
if(low>g[i].Pout)
low=g[i].Pout;
if(high<g[i].Pout)
high=g[i].Pout;
sum+=g[i].Pout;
i++;
}
avg=sum/n;
cout<<"\nThe Lowest Output Power :"<<low;
cout<<"\nThe highest Output Power :"<<high;
cout<<"\nThe Average Output Power :"<<avg;
}
OUTPUT
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us