Answers for "c code to python code converter online"

0

c code to python code converter online

#include<iostream>
// Defining MAX size to 10
#define MAX 10

using namespace std;

typedef struct Edge
{
  int source;
  int destination;
  int weight;
}Edge;

void bellman_ford_algo(int nodevertex,Edge edge[],int source_graph,int nodeedge)
{
  int u,v,weight,i,j=0;
  int distance[MAX];

  for(i=0;i<nodevertex;i++)
  {
    distance[i]=999;
  }

  // distance of source vertex
  distance[source_graph]=0;

  // free all the edges nodevertex - 1 times
  for(i=0;i<nodevertex-1;i++)
  {
    for(j=0;j<nodeedge;j++)
    {
      u=edge[j].source;
      v=edge[j].destination;
      weight=edge[j].weight;


      if(distance[u]!=999 && distance[u]+weight < distance[v])
      {
        distance[v]=distance[u]+weight;
      }
    }

  }

  // checking for negative cycle
  for(j=0;j<nodeedge;j++)
  {
    u=edge[j].source;
    v=edge[j].destination;
    weight=edge[j].weight;

    if(distance[u]+weight < distance[v])
    {
      cout<<"\n\nNegative Cycle present..!!\n";
      return;
    }
  }

  cout<<"\nVertex"<<"  Distance from source";
  for(i=1;i<=nodevertex;i++)
  {
    cout<<"\n"<<i<<"\t"<<distance[i];
  }

}


int main()
{
  int nodevertex,nodeedge,source_graph;
  Edge edge[MAX];

  cout<<"Enter the number of vertices you want : ";
  cin>>nodevertex;


  printf("Enter the source vertex of the graph: ");
  cin>>source_graph;

  cout<<"\nEnter no. of edges you want : ";
  cin>>nodeedge;

  for(int i=0;i<nodeedge;i++)
  {
    cout<<"\nEdge Number "<<i+1<<"=";
    cout<<"\nEnter source vertex here :";
    cin>>edge[i].source;
    cout<<"Enter destination vertex here:";
    cin>>edge[i].destination;
    cout<<"Enter weight here :";
    cin>>edge[i].weight;
  }

  bellman_ford_algo(nodevertex,edge,source_graph,nodeedge);

  return 0;
}
Posted by: Guest on March-27-2021
0

online c code to python code conversion

#include<stdio.h>
using namespace std;
void main()
{
  for (int i=1, i<=5, i++)
  {
    for(int j=1, j<=i,j++)
    {
      printf("%c",64+j)
    }
    printf("\n")
  }
}
Posted by: Guest on April-24-2021
0

c code to python code converter online

#include<iostream>
 using namespace std;
 #include<bits/stdc++.h>
 int has1[26],has2[26];
  int main()
   {
    int n;
      cin>>n;
        char ff[n+10],ss[n+10];
          for(int i=0;i<n/2;i++)
          {
              cin>>ff[i];
               has1[ff[i]-'a']++;
          }
            for(int i=0;i<n/2;i++)
            {

                  cin>>ss[i];
                  has2[ss[i]-'a']++;
            }
            sort(ff,ff+n/2);
              sort(ss,ss+n/2);
              //case 1
               int ans1=0,ans2=0,ans3=0;
              for(int i=0;i<26;i++)
              {
                  ans1+=abs(has1[i]-has2[i]);
                //    cout<<"i " <<i<<" " <<has1[i]<<" " <<has2[i]<<endl;

              }
              int i=0,j=0;
               while(i!=n/2  && j!=n/2)
               {
                   if(ff[i]<ss[j])
                   {

                        i++;
                         j++;
                   }
                   else
                    j++;

               }
               ans2=abs(j-i);


               i=0,j=0;
               while(i!=n/2  && j!=n/2)
               {
                   if(ss[i]<ff[j])
                   {

                        i++;
                         j++;
                   }
                   else
                    j++;

               }

            ans3=abs(j-i);
             // cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
            cout<<min(min(ans1/2,ans2),ans3);
        return 0;
      }
Posted by: Guest on April-22-2021
0

c code to python code converter online

#include<stdio.h>
#include<conio.h>
void main()
{
  int rows,i,j,k=0;
  printf("Enter number of rows: ");
  scanf("%d",&rows);
  for(i=1;i<=rows;i++)
  {
  for(j=1;j<=i;++j)
  printf("%d ",k+j);
  ++k;
  printf("\n");
  }
  getch();
}
Posted by: Guest on October-15-2021
-1

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()
Posted by: Guest on January-01-2021

Code answers related to "c code to python code converter online"

Python Answers by Framework

Browse Popular Code Answers by Language