TCS NQT Set 4 | Day 1 2020 | vikramaditya astrology

TCS NQT Set 4 | Day 1 2020 | vikramaditya astrology

TCS NQT Set 4 

Our hoary culture had several great persons since time immemorial and king vikramaditya’s nava ratnas (nine gems) belong to this ilk. They are named in the following shloka:TCS NQT Set 4

Among these, Varahamihira was an astrologer of eminence and his book Brihat Jataak is recokened as the ultimate authority in astrology. He was once talking with Amarasimha,another gem among the nava ratnas and the author of Sanskrit thesaurus, Amarakosha. Amarasimha wanted to know the final position of a person, who starts from the origin 0 0 and travels per following scheme.

He first turns and travels 10 units of distance
His second turn is upward for 20 units
The third turn is to the left for 30 units
The fourth turn is downward for 40 units
The fifth turn is to the right(again) for 50 units
… And thus he travels, every time increasing the travel distance by 10 units.

While Varahamitra could use his astrology skills to predict movement based on planetary positions, use your programming expertise to print the final position, given the number of turns(n);2<=n<=1000. This is TCS NQT Set 4 question

Logic:

  • Get the input from the user number steps needed to move
  • The initial position is origin ie,(0,0)
  • For positive x-axis increment 10 and for negative decrement 10
  • For positive y-axis increment 20 and for negative decrement 20
  • At last, we get the  destination(x,y)

Program:

#include<stdio.h>
void main()
{
    int x=10,y=20,d=0,n,i;
    scanf("%d",&n);
    for(i=2;i<n;i++)
    {
        d=10+i*10;        //each time extra 10 units are added
        if(i%2==0)
        {
            if(x<0)
            {
                x=d+x;    //positive x axis direction
            }
            else
            {
                x=x-d;    //negative x axis direction
            }
        }
        else
        {
            if(y<0)
            {
                y=d+y;    //positive y axis direction
            }
            else
            {
                y=y-d;    //negative y axis direction
            }
        }
    }
    printf("%d %d",x,y);
}

You might also like:

TCS NQT Day 1 | set3

Follow For Instant Updates

Join WhatsApp Group: link
Join our Telegram Channel: link
Like our Facebook Page:  link
Subscribe to our Youtube channel: link

Vignesh

A Computer Science graduate who likes to make things simpler. When he’s not working, you can find him surfing the web, learning facts, tricks and life hacks. He also enjoys movies in his leisure time.
5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x