convert python code to c online code example

Example 1: convert python code to c online

def main(str1, str2):
    m = len(str1)
    n = len(str2)
    j = 0    
    i = 0
    while j < m and i < n:
        if str1[j] == str2[i]:
            j = j+1
        i = i + 1
    return j == m
str2 = str(input())
N = int(input())
for i in range(N):
    str1 = str(input())
    if main(str1, str2):
        print("POSITIVE") 
    else:
        print( "NEGATIVE")

Example 2: convert python code to c online

# Raw Package
import numpy as np
import pandas as pd

#Data Source
import yfinance as yf

#Data viz
import plotly.graph_objs as go

#Interval required 1 minute
data = yf.download(tickers='UBER', period='1d', interval='1m')

#declare figure
fig = go.Figure()

#Candlestick
fig.add_trace(go.Candlestick(x=data.index,
                open=data['Open'],
                high=data['High'],
                low=data['Low'],
                close=data['Close'], name = 'market data'))

# Add titles
fig.update_layout(
    title='Uber live share price evolution',
    yaxis_title='Stock Price (USD per Shares)')

# X-Axes
fig.update_xaxes(
    rangeslider_visible=True,
    rangeselector=dict(
        buttons=list([
            dict(count=15, label="15m", step="minute", stepmode="backward"),
            dict(count=45, label="45m", step="minute", stepmode="backward"),
            dict(count=1, label="HTD", step="hour", stepmode="todate"),
            dict(count=3, label="3h", step="hour", stepmode="backward"),
            dict(step="all")
        ])
    )
)

#Show
fig.show()

Example 3: convert python code to c online

# cook your dish here
tc = int(input())
for _ in range(tc):
    c = 0
    n = int(input())
    n = pow(2,n)
    for x in range(0,n):
        a = x ^ (x+1)
        b = (x+2) ^ (x+3)
        if(a==b):
            c+=1
    print(c)

Example 4: convert python code to c online

x = 5
y = 10
print(x + y)

Example 5: convert python code to c online

def main():
  # 4 x 4 csr matrix
  #    [1, 0, 0, 0],
  #    [2, 0, 3, 0],
  #    [0, 0, 0, 0],
  #    [0, 4, 0, 0],
  csr_values = [2, 3, 1, 4,5]
  col_idx    = [1, 2, 0, 1,1]
  row_ptr    = [0, 2, 4,5]
  csr_matrix = [
      csr_values,
      col_idx,
      row_ptr
      ]

  dense_matrix = [
      [0, 3, 0],
      [1, 4, 5],
      [2, 0, 0],
      ]

  res = [
      [0, 0, 0],
      [0, 0, 0],
      [0, 0, 0],
      ]

  # matrix order, assumes both matrices are square
  n = len(dense_matrix)

  # res = dense X csr
  csr_row = 0 # Current row in CSR matrix
  for i in range(n):
    start, end = row_ptr[i], row_ptr[i + 1]
    for j in range(start, end):
      col, csr_value = col_idx[j], csr_values[j]
      for k in range(n):
        dense_value = dense_matrix[k][csr_row]
        res[k][col] += csr_value * dense_value
    csr_row += 1

  print(res) 


if __name__ == '__main__':
  main()