user40529: I am new to Arduino. I am learning from Arduino Cookbook. I was using tinkercad.com for running my Arduino code. But it is not working.
The Serial monitor should show the key which I have pressed on the keypad.
I think there is some syntactical error in the code, I believe the connection is all right. 
Any suggestion will be appreciated.
Please look into this:
const char keymap[4][4]={
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
 };
const int rpin[]={9,8,7,6};
const int cpin[]={5,4,3,2};
void setup()
{
  Serial.begin(9600);
  Serial.println("Program starting");//for debugging purpose and canbe removed later 
  for(int i=0;i<4;i++)
  {
    pinMode(rpin[i],INPUT);
    digitalWrite(rpin[i],HIGH);
  }
  for(int j=0;j<4;j++)
  {
    pinMode(cpin[j],INPUT);
    digitalWrite(cpin[j],HIGH);
  }
}
void loop()
{
  char key=getkey();
  if(key!=0)
  {
   Serial.println(key); 
  }  
}
char getkey()
{
  char key=0;
  for(int i=0;i<4;i++)
  {
    digitalWrite(rpin[i],LOW);
    for(int j=0;j<4;j++)
    {
      if (digitalRead(cpin[j])==LOW)
      key=keymap[i][j];
    }
    digitalWrite(rpin[i],HIGH);
  }
  return key;
}

and the connection pic:

update 1:


user32827: Cited comment:

Check pin modes. Should be INPUT_PULLUP and OUTPUT. Also, consider
  debouncing. – Mikael Patel

Please, try:
const char keymap[4][4]={
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
 };
const int rpin[]={9,8,7,6};
const int cpin[]={5,4,3,2};
void setup()
{
  Serial.begin(9600);
  Serial.println("Program starting");//for debugging purpose and canbe removed later 
  for(int i=0;i<4;i++)
  {
//Should be INPUT_PULLUP and OUTPUT
    pinMode(rpin[i],OUTPUT);
    pinMode(cpin[i],INPUT_PULLUP);
  }
}
void loop()
{
  char key=getkey();
  if(key!=0)
  {
   Serial.println(key);
   delay(200);              // Also, consider debouncing. 
  }  
}
char getkey()
{
  char key=0;
  for(int i=0;i<4;i++)
  {
    digitalWrite(rpin[i],LOW);
    for(int j=0;j<4;j++)
    {
      if (digitalRead(cpin[j])==LOW)
      key=keymap[i][j];
    }
    digitalWrite(rpin[i],HIGH);
  }
  return key;
}


40529: <p>I am new to Arduino. I am learning from Arduino Cookbook. I was using <a href="https://www.tinkercad.com/circuits" rel="nofollow noreferrer">tinkercad.com</a> for running my Arduino code. But it is not working.
The Serial monitor should show the key which I have pressed on the keypad.
I think there is some syntactical error in the code, I believe the connection is all right. 
Any suggestion will be appreciated.
Please look into this:</p>

<pre class="lang-cpp prettyprint-override"><code>const char keymap[4][4]={
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
 };
const int rpin[]={9,8,7,6};
const int cpin[]={5,4,3,2};
void setup()
{
  Serial.begin(9600);
  Serial.println("Program starting");//for debugging purpose and canbe removed later 
  for(int i=0;i&lt;4;i++)
  {
    pinMode(rpin[i],INPUT);
    digitalWrite(rpin[i],HIGH);
  }
  for(int j=0;j&lt;4;j++)
  {
    pinMode(cpin[j],INPUT);
    digitalWrite(cpin[j],HIGH);
  }
}
void loop()
{
  char key=getkey();
  if(key!=0)
  {
   Serial.println(key); 
  }  
}
char getkey()
{
  char key=0;
  for(int i=0;i&lt;4;i++)
  {
    digitalWrite(rpin[i],LOW);
    for(int j=0;j&lt;4;j++)
    {
      if (digitalRead(cpin[j])==LOW)
      key=keymap[i][j];
    }
    digitalWrite(rpin[i],HIGH);
  }
  return key;
}
</code></pre>

<p>and the connection pic:</p>

<p><a href="https://i.stack.imgur.com/xuHI6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xuHI6.png" alt="enter image description here"></a></p>

<p>update 1:
<a href="https://i.stack.imgur.com/uuQ41.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uuQ41.png" alt="enter image description here"></a></p>
 32827: <p>Cited comment:</p>

<blockquote>
  <p>Check pin modes. Should be INPUT_PULLUP and OUTPUT. Also, consider
  debouncing. – Mikael Patel</p>
</blockquote>

<p>Please, try:</p>



<pre><code>const char keymap[4][4]={
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
 };
const int rpin[]={9,8,7,6};
const int cpin[]={5,4,3,2};
void setup()
{
  Serial.begin(9600);
  Serial.println("Program starting");//for debugging purpose and canbe removed later 
  for(int i=0;i&lt;4;i++)
  {
//Should be INPUT_PULLUP and OUTPUT
    pinMode(rpin[i],OUTPUT);
    pinMode(cpin[i],INPUT_PULLUP);
  }
}
void loop()
{
  char key=getkey();
  if(key!=0)
  {
   Serial.println(key);
   delay(200);              // Also, consider debouncing. 
  }  
}
char getkey()
{
  char key=0;
  for(int i=0;i&lt;4;i++)
  {
    digitalWrite(rpin[i],LOW);
    for(int j=0;j&lt;4;j++)
    {
      if (digitalRead(cpin[j])==LOW)
      key=keymap[i][j];
    }
    digitalWrite(rpin[i],HIGH);
  }
  return key;
}
</code></pre>
