Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
March 12, 2021 09:34 am GMT

C Vs Python Syntax Difference

In my humble opinion learning, by comparison, is the best way of learning, To stay in the loop while the industry is moving extremely rapidly, learning complex concepts by comparing to already familiar stuff is our best bet.

In this blog post, I will show you some common programs implemented in python and C++, So if you are trying to learn one of those languages or both at the same time! this post will serve you to learn in a comparable manner, let's dive in!

Hello World Program

  1. Hello World Program in python
print("Hello, World!")
  1. Hello World Program in C++
#include <iostream>int main() {    std::cout << "Hello World!";    return 0;}

Display Fibonacci Series

  1. Display Fibonacci Seriesin python
nterms = int(input("How many terms you want? "))  # first two terms  n1 = 0  n2 = 1  count = 2  # check if the number of terms is valid  if nterms <= 0:     print("Please enter a positive integer")  elif nterms == 1:     print("Fibonacci sequence:")     print(n1)  else:     print("Fibonacci sequence:")     print(n1,",",n2,end=', ')     while count < nterms:         nth = n1 + n2         print(nth,end=' , ')         # update values         n1 = n2         n2 = nth         count += 1  }
  1. Display Fibonacci Series in C++
#include <iostream>  using namespace std;  int main() {    int n1=0,n2=1,n3,i,number;     cout<<"Enter the number of elements: ";     cin>>number;     cout<<n1<<" "<<n2<<" "; //printing 0 and 1     for(i=2;i<number;++i) //loop starts from 2 because 0 and 1 are already printed     {      n3=n1+n2;      cout<<n3<<" ";      n1=n2;      n2=n3;     }       return 0;     } 

weather If you already know cpp and trying to learn python or vice-versa I hope you get the general gist of the Syntax difference between the two languages,
If you like this and this method of learning things, I have a repository dedicated to comparing programming languages and concepts, you can check it out on github


Original Link: https://dev.to/zeshama/same-programs-different-languages-3o3b

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To