The Torris County Visa Center generates the
token number for its applicants from their
application ID. The application ID is a numeric
value. The token number is generated in a
specific form. The even digits in the applicant's
ID are replaced by the digit one greater than
the even digit and the odd digits in the
applicant's ID are replaced by the digit one
lesser than the odd digit. The numeric value
thus generated represents the token number
of the applicant. write an algorithm to generate the token number from the applicant id
Answers
Answered by
44
Explanation:
#include <stdio.h>
#include<stdlib.h>
int main()
{
int n,count=0;
scanf("%d",&n);
char str[100];
sprintf(str, "%d", n);
for(int i=0;str[i] != '\0';i++)
{
if(str[i]%2==0)
{
++(str[i]);
}
else
{
--(str[i]);
}
}
int output-atoi (str); printf("%d",output);
}
Answered by
0
Answer:
The algorithm to generate the token number from the applicant id is as follows:
- Declare variables to store the application id, token number, counter of the for loop, and an array to separate the numbers from the application id and store them separately.
- Take the application id as the input from the user.
- Separate the digits of the application id and store them in an array using the for loop.
- Check whether each digit stored in the array is even or odd.
- If the digit is even, its value is incremented by one.
- If the digit is odd, its value is decremented by one.
- The token number is calculated and displayed using the for loop.
#SPJ3
Similar questions