Inlab 1
Nature of Digit in Position (Id = 2612)
Question:
Given a number ‘n’ and a position; Write an algorithm and subsequent ‘C’ program to Check if the ‘p-th’ Digit, Starting from left-most digiit of the number of the number ‘n’ is ‘odd’ or ‘even’.For most 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 to accept numbers of large size.
Input Format:
The first line contains the number, n
The second line contains the position, p
Output Format:
Print either ‘Odd’ or ‘Even’
Input the first line contains the number as "n"
the second line contains the position as "p"
Display ‘Odd’ or ‘Even’
INPUT
OUTPUT
PROCESSING
C PROGRAM
declared variacble n, p,c;
Initialized an array a size of 100
while(n>0)
a[c++] equals n mod 10
n equals n divided by 10
check whether a[c-p] mod 2 equals 1
display “Odd”
otherwise
display “Even”
#include<stdio.h>
void main()
{
int n;
int a[100],p,c=0;
scanf("%d%d",&n,&p);
while(n>0)
{
a[c++]=n%10;
n=n/10; }
if(a[c-p]%2==1)
printf("Odd");
else printf("Even");
}