Doubt for video

#include
using namespace std;
int main()
{ int i,n,ans=0;
cin>>n;
n=n/2;
cout<<n*(n+1);
return 0;
}

How to decide which code to use? This code is also giving correct answer? Is the code in the video more efficient or is this more efficient?

Hey Sonali, mention the video’s name as well as the time stamp of code which you are talking about.

while loop sum of even numbers

whole video is regarding the code

Hey Sonali, we can write code for a given problem in many different ways and its obvious that the code you have written is more efficient as its time complexity is O(1), but the video is just to teach you the concept of while loop and its use cases.