C Saved Program: placid-af

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include<stdio.h>
int keycomp(int key);
int num(int num_arr);


int main()
{
    int key, result;
    int num_arr1, num_arr2, num_arr3, num_arr4, num1, num2, num3, num4;
 int array[12];
    
   int i;
 
printf("enter the elements of array\n");
   for(i=0;i<=12;i++)
   {
       if(i<3)
{
    scanf("%d", &array[i]);
 num_arr1=array[i];
 num1=num(num_arr1);
 
}
if((i>3)&&(i>6))
{
    scanf("%d", &array[i-3]);
num_arr2=array[i-3];
num2=num(num_arr2);


}
if((i>6)&&(i>9))
{
    scanf("%d", &array[i-6]);
num_arr3=array[i-6];
num3=num(num_arr3);

}
if((i>9)&&(i>12))
{
    scanf("%d", &array[i-9]);
num_arr3=array[i-9];
 num4=num(num_arr4);

}

   }
    
    
    
   
    
   key=(int)1000*num1+100*num2+10*num3+1*num4;
   printf("%d\n", key);
   
   result=keycomp(key);
 
} 
int keycomp(int key)
{
int keyset[4]={6421,1245,2546,5423};
if(key!=keyset[0])
{
printf(" sorry try again\n");
}else if(key!=keyset[1])
{
printf(" sorry try again\n");
}else if(key!=keyset[2])
{
printf(" sorry try again\n");
}else if(key!=keyset[4])
{
printf( "sorry try again\n");
}else
printf("congratulations you won\n");
return 0;

}
int num(int num_arr)
{
int array[3];
int num;
int j=0;
   num=(int)array[j]*4+array[j+1]*2+array[j+2]*1;
   switch(num)
   {
       case 0:
       num=7;
       printf("%d\n", num);
       break;
       case 1:
       num=3;
       printf("%d\n", num);
       break;
       case 2:
       num=6;
       printf("%d\n", num);
       break;
       case 3:
       num=1;
       printf("%d\n", num);
       break;
       case 4:
       num=4;
       printf("%d\n", num);
       break;
       case 5:
       num=5;
       printf("%d\n", num);
       break;
       case 6:
       num=2;
       printf("%d\n", num);
       break;
       case 7:
       num=8;
       printf("%d\n", num);
       break;
       
   }
   return num;
}
   
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs