C program to print Nth number in a series
To find Nth number in series of
0 0 1 2 2 4 3 6 4 8 5 ........................
The above series even index contains whole numbers and odd index contains even numbers.
The above series even index contains whole numbers and odd index contains even numbers.
When given Nth index number the number at that position is to be printed.
Input:
First line of input contains Nth index number
Output:
Number at Nth index should be printed
Input:
First line of input contains Nth index number
Output:
Number at Nth index should be printed
Example:
Input:
10
Output:
5
Explanation:
In the above example
When we enter 10 index number then at that 10 index number 5 is present.
0 0 1 2 2 4 3 6 4 8 5
SOURCE CODE:
#include<stdio.h>
int main()
{
int n,i,j,e=0,od=0,k;
long int a[10000]={0};
scanf("%d",&n);
for(i=2;i<=n;)
{
if(i%2==0)
{
e=e+1;
a[i]=e;
}
else
{
od=od+2;
a[i]=od;
}
i++;
}
for(i=0;i<=n;i++)
{
if(i==n)
printf("%d ",a[i]);
}
return 0;
}
Output:
5
Explanation:
In the above example
When we enter 10 index number then at that 10 index number 5 is present.
0 0 1 2 2 4 3 6 4 8 5
SOURCE CODE:
#include<stdio.h>
int main()
{
int n,i,j,e=0,od=0,k;
long int a[10000]={0};
scanf("%d",&n);
for(i=2;i<=n;)
{
if(i%2==0)
{
e=e+1;
a[i]=e;
}
else
{
od=od+2;
a[i]=od;
}
i++;
}
for(i=0;i<=n;i++)
{
if(i==n)
printf("%d ",a[i]);
}
return 0;
}
ReplyDeletethank u for sharing this post Meraki Firewall
Meraki Cloud