#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))
import java.util.Scanner;
public class q7 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(“enter value of n : “);
int n = sc.nextInt();
int a =0;
if(n%2==0){
for(int i =0; i<n/2; i++){
int N = n/2;
int res = a + (N-1)*1;
System.out.println(res);
break;
}
}
else{
for(int i =0; i<(n/2)+1; i++){
int N = (n+1)/2;
int res = a + (N-1)*2;
System.out.println(res);
break;
}
}
}
}
public class Main
{
public static void main(String[] args) {
int num = 16;
System.out.println((num % 2 == 0) ? (num / 2) – 1 : (num / 2) * 2);
}
}
Using Java Code :-
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println(“Enter Any Number.”);
int num=s.nextInt();
System.out.println(num%2!=0? (int)Math.abs(num-1):(int)Math.abs((num/2)-1));
}
}
Using Java Code:-
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println(“Enter Any Number.”);
int num=s.nextInt();
System.out.println(num%2!=0? (int)Math.abs(num-1):(int)Math.abs((num/2)-1));
}
}
/******************************************************************************
Using Java Code
0,0,2,1,4,2,6,3,8,4,10,5,12,6,14,7,16,8
odd:- 0 2 4 6 8 10 12 14 16 ….
even:- 0 1 2 3 4 5 6 7 8….
*******************************************************************************/
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println(“Enter Any Number.”);
int num=s.nextInt();
System.out.println(num%2!=0? (int)Math.abs(num-1):(int)Math.abs((num/2)-1));
}
}