VIT SKILL RACK SOLUTIONS

CSC 1002 SKILLRACK SOLUTION InLab 1 WINTER SEM



Solutions for Skillrack CSE1002 Inlab1


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, nThe second line contains the position, pOutput 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



zero

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments:

Post a Comment