Friday 27 July 2018

Team Event
 
Super Quiz Bee is a famous quiz Competition that tests students on a wide variety of academic subjects. This week’s competition was a Team event and students who register for the event will be given a unique registration code N. The participants are teamed into 10 teams and the team to which a participant is assigned to depends on the absolute difference between the first and last digit in the registration code.
 
The event organizers wanted your help in writing an automated program that will ease their job of assigning teams to the participants. If the registration number given is less than 10, then the program should display "Invalid Input".

 
Input Format:
The only line of input contains an integer N.

Output Format:
Output the absolute difference between the first and last digit of N.
Refer sample input and output for formatting specifications.


Sample Input 1:
345

Sample Output 1:
2

Sample Input 2:
9

Sample Output 2:
Invalid Input


Solution:
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,s,i[10],a,g;
    scanf("%d",&n);
    if(n/10==0)
    printf("Invalid Input");
    else
    {
    for(a=0;n!=0;a++)
    {
    s=n%10;
   
    n=n/10;

    i[a]=s;
    }
    
    g=abs(i[0]-i[a-1]);
    printf("%d",g);
    }
    return(0);

}

3 comments:

Random password generator in Java

       Random password generator in Java Source code: mport java.io.*; import java.util.*; public class Main { public static void main(Str...