Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

need a c program

0 votes
asked Mar 5, 2019 by anonymous

Pin code security check: Write a C program to validate the security pin codes in the

following way:

  • It first checks if the pin code entered is six digits. If not, the code is invalid.

  • It then checks if each digit within the six-digit pin is divisible by 2. If not, the

    code is invalid.

  • Itthenchecksifthesumofallthedigitsislessthan30,thenthecodeisinvalid.

  • If ten consecutive invalid pins are entered, the system locks out and reports an

    intruder. 

2 Answers

+1 vote
answered Mar 5, 2019 by Lohith Yadav
#include <stdio.h>
#include<string.h>

int main()
{
    int count=0;
    while(count<10)
    {
         char pincode[100];
         int sum=0,l=0;
        printf("Enter Pincode\n");
        scanf("%s",pincode);
        if(strlen(pincode) == 6)
        {
            l++;
          if(pincode[5]=='0' || pincode[5]=='2' ||pincode[5]=='4' || pincode[5]=='6' || pincode[5]=='8')
           {
               l++;
               for(int i=0;i<6;i++)
                {
                  sum=(pincode[i]-48)+sum;
                }
               if(sum > 30)
                {
                    count=0;
                    l++;
                  printf("Valid PinCode\n");
                }
           }
        }
        if(l < 3)
        {
            count++;
            printf("Invalid Pincode\n");
        }
    }
    printf("Sorry Your Limit Has Been Exceeded\n");
    return 0;
}
0 votes
answered Mar 6, 2019 by suryateja (140 points)
#include<stdio.h>
int main()
{
    int sum=0,n,r,count=0,numcount=0,m,r1,r2,r3,r4,r5,r6;
    while(count<10)
    {
        printf("Enter pin code\n");
        scanf("%d",&n);
        m=n;
        r1=n%10;
        n/=10;
        r2=n%10;
        n/=10;
        r3=n%10;
        n/=10;
        r4=n%10;
        n/=10;
        r5=n%10;
        n/=10;
        r6=n%10;
        while(m!=0)       
        {  
            numcount++;
            r=m%10;
            sum+=r;
            m/=10;
           
        }
        if(numcount!=6||sum<30||r1%2!=0||r2%2!=0||r3%2!=0||r4%2!=0||r5%2!=0||r6%2!=0)
        {
            printf("Invalid code\n");
            count++;
        }
        else
        {
            printf("code is valid you can proceed\n");
            break;
        }
    }
    if(count>10)
    {
        printf("your out of chances\n");
    }
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...