As a safety precaution banks provide a feature that during any ATM transaction if someone comes and attacks, then the customer can enter the ATM pin in reverse order. This sends a message to the nearest police station. However if the reversed pin is the same as he original pin then no alarm is created. The bank needs a software application that checks that a user chooses an ATM pin whose reverse is not the same number. A software need to be developed with following requirements using while loop.
a. Read the pin number
b. Calculate the reverse the pin number
c. if the reversed pin is same as original pin then inform the user that this is an invalid pin number
#include <stdio.h>
#include <stdlib.h>
int main(){
int PIN;
//a. Read the pin number
printf("Enter PIN: ");
scanf("%d",&PIN);
int curentPIN=PIN;
//b. Calculate the reverse the pin number
int reversedPIN=0;
int remainder;
while(curentPIN != 0) {
remainder = curentPIN%10;
reversedPIN = reversedPIN*10 + remainder;
curentPIN /= 10;
}
//c. if the reversed pin is same as original pin then inform the user that this is an invalid pin number
if(reversedPIN==PIN){
printf("\nThis is an invalid PIN number.\n");
}else{
printf("\nThis is VALID PIN number.\n");
}
getchar();
getchar();
return 0;
}
Comments
Leave a comment