### Solutions for Skillrack CSE1002 Inlab 1

Total time : 20 mins

Challenges : 1

### Question (Nature of Digit in Position)

Given a number ‘n’ and a position ‘p’, write an algorithm and the subsequent ‘C’ program to check if the ‘p-th’ digit from the leftmost position of ‘n’ is odd or even. For example, if ‘n’ is 3145782 and p is 4 then you have to check if 5 is odd or even. Since it is odd print ‘Odd’. Make your code accept numbers of larger size.

Input Format:

The first line contains the number, n

The second line contains the position, p

Output Format:

Print either “Odd” or “Even”

### Solution

#include< stdio.h > void main() { int p,i=0,a[10]; long int n; scanf("%d%d",&n,&p); while(n > 0) { a[i++]=n%10; n/=10; } if(a[i-p]%2==0) printf("Even"); else printf("Odd"); }

### Input

INPUT: 3145782 4

### Output

OUTPUT: Odd

Advertisements