#include<stdio.h>
int main()
{
int i, n, a=0, b=0;
printf("enter number : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2!=0)
{
if(i>1)
a = a + 2;
}
else
{
b = a/2;
}
}
if(n%2!=0)
{
printf("%d",a);
}
else
{
printf("%d",b);
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int i, n, a=0, b=0;
cout << "enter number : ";
cin >> n;
for(i=1;i<=n;i++)
{
if(i%2!=0)
{
if(i>1)
a = a + 2;
}
else
{
b = a/2;
}
}
if(n%2!=0)
{
cout << a;
}
else
{
cout << b;
}
return 0;
}
//Java program to find nth element of the series
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a = 0, b = 0;
if(n % 2 == 0)
{
for(int i = 1 ; i <= (n-2) ; i = i+2)
{
a = a + 2;
b = a / 2;
}
System.out.print(b);
}
else
{
for(int i = 1 ; i < (n-2) ; i = i+2)
{
a = a + 2;
b = a / 2;
}
a = a + 2;
System.out.print(a);
}
}
}
n = int(input('enter the number:'))
a=0
b=0
for i in range(1,n+1):
if(i%2!=0):
a= a+2
else:
b= b+1
if(n%2!=0):
print('{}'.format(a-2))
else:
print('{}'.format(b-1))
#include
using namespace std;
int main()
{
int n;
cin>>n;
int ans;
if(n%2==0)
{
ans=(n/2-1);
}
else
{
ans=(n/2*2);
}
cout<<ans;
}
//will this work
#include
using namespace std;
int main(){
int n;
cin>>n;
if(n%2==0 && n>0){
cout<<(n-2)/2<<endl;
}
else{
cout<<n-1;
}
}
python code
position= int(input())
if position % 2 !=0:
print(position-1)
else:
print((position//2)-1)
n = int(input(“Enter a number : “))
print(‘0 0’)
i = 2
for i in range(2,n+1):
if(i%2==0):
print(i,” “)
else:
print((i-1)/2,” “)
#include
void even(int n)
{
int y = n ;
printf(“%d”,y);
}
void odd(int n)
{
int x = n ;
printf(“%d”, x);
}
void main()
{
int n;
scanf(“%d”,&n);
if(n%2 != 0)
{
odd(n/2);
}
else
{
even (n);
}
}
even this code runs perfectly for the given problem
#include
using namespace std;
int main()
{
int n,r;
cin>>n;
if(n%2==0)
{
r=(n-2)/2;
}
else
{
r=n-1;
}
cout<<r;
}
*** Simply by understanding the series, we can solve these type of problems without any logic ***
********************* JAVA code **********************
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
if(N==1 || N==2) {
System.out.println(“0”);
}
else if(N%2 == 0) {
System.out.println((N-2)/2);
}
else {
System.out.println(N-1);
}
}
}
num=int(input(“enter the number:”))
if num%2==0:
z=num//2
x=z-1
print(x)
else:
y=num-1
print(y)
Python code
a=int(input())
if a%2==0:
print(a//2-1)
else:
print(a-1)
a=int(input())
if a%2==0:
print(a//2-1)
else:
print(a-1)
n=int(input())
a=0
if (n==1) or (n==2):
print(a)
elif(n % 2 ==0):
print((n-1)//2)
else:
print(n-1)
x = int(input())
l = []
for i in range(x):
l.append(2 * i)
l.append((i))
print(l)