An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
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
- Hello World Program in python
print("Hello, World!")
- Hello World Program in C++
#include <iostream>int main() { std::cout << "Hello World!"; return 0;}
Display Fibonacci Series
- 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 }
- 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
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To