Monday, 25 December 2017

Finding the day using the given date

     

  Hello,here you can find the program which gives what will be the day of the date you asked.
         This program works on the principle of odd days.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int day,month,year,odd=0,m[12]={3,0,3,2,3,2,3,3,2,3,2,3},i,rem=-1,ch;
clrscr();
scanf("%d %d %d",&day,&month,&year);
if(day<=31 && day>0 && month>0 && month<=12 &&year>0)
{
odd=odd+day;
for(i=0;i<month-1;i++)
odd+=m[i];
       rem=year%400;

       if(rem<=200 && rem>0){
       for(i=1;i<rem;i++)
       {
if((i%4)==0)
{
odd+=2;
}
else
{
odd+=1;
}
       }
       }
       else if(rem>200)
       {
rem=400-rem;
for(i=rem;i>1;i--)
{
if((i%4)==0) odd+=2;
else
odd+=1;
}
       }
       if(rem==0) odd--;
       ch=odd%7;
       switch(ch)
       {
case 0:printf("SUNDAY");
break;
case 1:printf("MONDAY");
break;
case 2:printf("TUESDAY");
break;
case 3:printf("WEDNESDAY");
break;
case 4:printf("THURSDAY");
break;
case 5:printf("FRIDAY");
break;
case 6:printf("SATURDAY");
break;
       }
    }
    else
printf("Error in the date you have mentioned\n");
}

Output:





If you want to know the principle of odd days comment below,i am sured that i will explain.

    Thank you and keep supporting me.

Wednesday, 13 December 2017

HIDDEN FACTS - 01

              I will be watching you
     
 The topic is I WILL BE WATCHING YOU. It's not a Kamal Hassan's dialogue and not a Big boss show.It's about ours.

Then who is watching me??!!
      Now a days,most of the people used Android mobile.That is watching you and controls you. If somebody buy a new android mobile. It ask to create a new Google account and link with mail id. If you install any apps, it will ask to link with Google account.
Then only you will access the app.Then you will install Facebook, Whatsapp,Twitter, Hike,Flipkart, skype and all Other social media's because now it's necessary for everybody.

If anything browse in Google, ads are in the websites.The website ads are what we are browse in the Google that's show or show some unnecessary ads.
Some apps in the Android are unnecessary permission are asking for access the apps.

 If you browse anything , seeing youtube videos,apps or whatever do in this android mobile.Whatever access in the Android mobile it's appear on my activity.It is closely watch your movements and save in my activity.So, if you don't want that to save my histories means Go to my activity - more - privacy,lock your privacy policies there or otherwise you can do it open new incognito tab and now kingdom of android mobile article coming soon........

The above content is not to harm anybody. If any mistakes, wrong facts and I'm not mentioned anything are share in the comment box.

Tuesday, 12 December 2017

Printing a matrix in spiral order(Spiral Matrix)

       In this post,We will see how to print a matrix in spiral format of clockwise direction.

If the matrix of 3×3 is  [1 2 3
                                           4 5 6
                                           7 8 9]
Then it is printed in spiral format in clockwise direction as , 1 2 3 6 9 8 7 4 5.

         
 If the matrix is of 4×4 or higher ,it should be printed in the following order.




                                
 -> First ,We should start from left to right direction. Where dir=0.

->  Then ,from top to bottom direction.
       Where dir=1.
->Then ,from right to left direction.Where 
    dir=2.
 
->Then ,from bottom to top.Where dir=3.

Here, the variable 'dir' is used to specify the direction.

->The variables  'T' (top) -> points 0th row.

->The variable 'B' (bottom)-> points to mth row.

->The variable 'L' (left)-> points to 0th column.

->The variable 'R' (right)-> points to nth column.


Program:

#include<iostream>
using namespace std;
int main()
{
   int Mat[10][10];
    int dir=0;
    int T,B,L,R;
    int m,n;
    cout<<"Give the order of the matrix"<<endl;
    cin>>m>>n;

    T=0;
    B=m-1;
    L=0;
    R=n-1;
    for(int i=0;i<m;i++)
        for(int j=0;j<n;j++)
            cin>>Mat[i][j];
    while(T<=B && L<=B)
    {
        if(dir==0)  
        {
            for(int k=L;k<=R;k++)
                cout<<Mat[T][k];
            T++;
        }
        if(dir==1)
        {
            for(int k=T;k<=B;k++)
                 cout<<Mat[k][R];
            R--;
        }
        if(dir==2)

        {
            for(int k=R;k>=L;k--)
                cout<<Mat[B][k];
            B--;
        }
        if(dir==3)
        {
            for(int k=B;k>=T;k--)
                cout<<Mat[k][L];
            L++;
        }
        dir=(dir+1)%4;
    }
}



Output:




HIDDEN FACTS - 00

             We start hidden facts series. In this series we discuss about hidden facts in this world.

what contents are in this series?
             In this series we discuss about entertainment, music, art,fashion, costumes, suggestions, stories, places, destroyed things, destroyable things, gadget, natural,food, tech news, cultures, leaders,human beings,automobiles ,animals, etc,. So, if you feel miss something means comment.Give your support.The respective articles are coming soon.......

Sunday, 10 December 2017

Pattern printing using asterix in shape of Q

     
   Pattern printing is to arrange the symbols.

In this program,I arranged the asterix symbol in the shape of Q.
Like the below,
            
                  ********
                  *             *
                  *             *
                  *             *
                  *         *  *
                  *           **
                  ********          
                                  *

 Program:

#include<iostream>
using namespace std;
int main()
{
    int i;
    for(i=0;i<=7;i++)
    {
        switch(i)
        {
            case 1:cout<<"******"<<endl;           break;
            case 2:cout<<"*       *"<<endl;break;
            case 3:cout<<"*       *"<<endl;break;
            case 4:cout<<"*    * *"<<endl;break;
            case 5:cout<<"*     **"<<endl;break;
            case 6:cout<<"******"<<endl;break;
            case 7:cout<<"           *"<<endl;break;
        }
    }
}

Sample outlet:


Alternate sorting


   Alternate sorting is a problem of testing the knowledge of using loops and conditional statements. 

Problem:

           Given an array of integers,rearrange the array in such a way that first element is 
first maximum and the second element is 
first minimum.
   Eg:
        Input:  1,2,3,4,5,6,7
        Output: 7,1,6,2,5,3,4

Program:


#include<iostream>
using namespace std;
int main()
{
    int arr[50],n,i,j;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    for(i=0;i<n-1;i++)
    {
        for(j=i;j<n;j++)
        {
            if(i%2==0)
            {
               if(arr[i]<arr[j])
                {
                    int temp=arr[i];
                    arr[i]=arr[j];
                    arr[j]=temp;
                }
            }
            else
            {
                if(arr[i]>arr[j])
                {
                     int temp=arr[i];
                      arr[i]=arr[j];
                      arr[j]=temp;
                }
            }
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<arr[i]<<endl;
    }
}

Output:


Saturday, 9 December 2017

Array sorting based weight of elements

Problem:  Given a set of numbers like <10, 36, 54,89,12> we want to find sum of weights based on the following conditions

    1. 5 if a perfect square

    2. 4 if multiple of 4 and divisible by 6

    3. 3 if even number

And sort the numbers based on the weight and print it as follows

<10,its_weight>,<36,its weight><89,its weight>

Should display the numbers based on increasing order.

Program:

#include<iostream>
#include<math.h>
using namespace std;
bool even(int x);
bool divisible(int x);
bool perfectsqr(int x);
int main()
{
    int arr[5]={10,36,54,89,12};
    int sum[5],i,temp;
    for(i=0;i<5;i++)
    {
         sum[i]=0;
         if(perfectsqr(arr[i]))
                sum[i]=sum[i]+5;
         if(divisible(arr[i]))
                sum[i]=sum[i]+4;
         if(even(arr[i]))
                sum[i]=sum[i]+3;
       
    }
    for(i=0;i<4;i++)
    {
        for(int j=i;j<5;j++)
        {
            if(sum[i]<sum[j])
            {
                 temp=sum[i];
                 sum[i]=sum[j];
                 sum[j]=temp;
                 temp=arr[i];
                 arr[i]=arr[j];
                 arr[j]=temp;
            }
        }
    }
    for(i=0;i<5;i++)
    {
        cout<<"<"<<arr[i]<<","<<sum[i]<<">";
        if(i!=4)
        cout<<",";
    }
    return 0;
}
bool even(int x)
{
    if(x%2==0)
        return 1;
    else
        return 0;
}
bool divisible(int x)
{
    if(x%4==0 && x%6==0)
        return 1;
    else
        return 0;
}
bool perfectsqr(int x)
{
   int ires;
    float fres=sqrt(x);
    ires=fres;
    if(ires==fres)
        return 1;
    else
        return 0;
}
Sample output:



Friday, 8 December 2017

Pattern printing (in a single loop)


Problem:


               Print the following pattern.

                              P          m
                                r      a
                                  o  r
                                    g 
                                  o  r
                                r      a
                              P          m

Criteria:

        One single for loop should be used (or) thecomplexity of the program should be O(n).



#include<iostream>
using namespace std;
int main()
{
    char str[20]="Program";
    int i;
    for(i=0;i<10;i++)
    {
        char out[20]="          "; 
        out[i]=str[i];
        out[6-i]=str[6-i];
        cout<<out;
        cout<<"\n";
    }
    return 0;

}    

SaSample output:

mple output:


   




Monday, 4 December 2017

Finding immediate greater


In this post,I demonstrate a problem which is asked in zoho interviews.

So, i think tis will be usefull for the people who are preparing for their
job interviews.

Question:

Find immediate greater in an array

An array of 'n' elements is given,
immediate greater element for every element should be found in the array.

Input:
6 4 3 9 5

Output:
6->9 4->5 3->4 9-> 5->6


Algorithm:

1.Get the elements in an array.
2.Sort the elemens in the separate another array.
3.Take an element in unsorted array and find its position in
   sorted array and its next element is its immediate greater.
4.Do the same process for all elements.
5.If its positiion in sorted array is n-1,then it do not have
  any greater element to it.

Program:

#include<stdio.h>

#include<conio.h>
int arr[50],sort[50],n;
int search(int a);
void sorting();
void main()
{
int i,j;
clrscr();
printf("Enter no. of elements in the array\n");
scanf("%d",&n);
printf("Enter array elements\n");
for(i=0;i<n;i++)
      {
scanf("%d",&arr[i]);
sort[i]=arr[i];
       }
sorting();
for(i=0;i<n;i++)
{
j=search(arr[i]);
if(j+1==n){printf("%d->\t",arr[i]);}
else
printf("%d->%d\t",arr[i],sort[j+1]);
}
getch();
}
void sorting()
{
int i,j,temp;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(sort[i]>sort[j])
    { temp=sort[i];
sort[i]=sort[j];
sort[j]=temp;
    }
}
}
return;
}
int search(int a)
{
int i;
for(i=0;i<n;i++)
{
if(a==sort[i])
return i;
}
}


Hope you understand the problem and the solution for it.
Any questions or complexity in explanation ask in comments.
                           Thank you.

Friday, 1 December 2017

Binary to decimal conversion using recursion


// CONVERSION OF BINARY TO DECIMAL USING RECURSION


/*PROCEDURE
   1.Eg:  Take a binary number as 1110
   2.1   1   1 0
       |    |    |    |->multiplyby2^0=result0
               |    |    |->multiply by 2^1  =result1
               |    |->multiply by 2^2  =result2
               |->multiply by 2^3  =result 3

  3.Final ,the converted decimal number=result0+result1+result2+result3

*/


#include<stdio.h>
#include<string.h>
#include<math.h>


int todecimal(char bin[50],int len);
int len; //Using ‘len’ as global variable is optional

void main()
{
char bin[50];
int dec;
clrscr();
printf("Enter the binary number\n");
scanf("%s",bin);
len=strlen(bin);
dec=todecimal(bin,len);
printf("%d",dec);
getch();
}
int todecimal(char bin[50],int l)
{
      if(len-l==len)
return 0;
      else
      {
   if(bin[len-l]=='0')
return todecimal(bin,l-1);
   else
return 1*pow(2,l-1)+todecimal(bin,l-1);
      }
}

Any doubts ask it in comments.
Finally share this program,if you like this.
                             Thank you.

Tuesday, 28 November 2017

Display linklist in reverse order


     
// C program reversing the Linklist (or)
Display the Linklist in reverse order

//Procedure
    //1.Use two pointer to print the last element and delete the last element
    //2.Repeat it for 'n' times,
    // where n=length of the list.
    //That is,every time last element is printed and is deleted from the list.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

//Declaration of structure of link list
struct node
{
int data;
struct node *next;
}ptr1;


void main()
{
int x,ch,n=0,i;
struct node *ptr2,*head,*ptr1;
clrscr();
printf("\t\tCreate the list\n");
printf("\t***************************\n");

// Creaion of Linklist
head=(struct node*)malloc(sizeof(struct node));
ptr1=head;
do
{
printf("Enter the data part of the node\n ");
scanf("%d",&ptr1->data);
ptr1->next=(struct node*)malloc(sizeof(struct node));
ptr1=ptr1->next;

printf("do you want to continue(1/0)\n");
scanf("%d",&ch);
n++;
}while(ch);

// Here,'n' records the length of the list
i=0;

//display ilst in reverse order
while(i<n)
{
ptr1=head;
while(ptr1->next != NULL)
{
ptr2=ptr1;
ptr1=ptr1->next;
}
printf("%d\n",ptr2->data); //Printing the last element


ptr2->next=NULL; //Deleting the last element

i++;

}
getch();
}

Hey,guys hope you understand this program.

Any queries,suggestions and alternative way solutions are welcomed.

If you want programs for some other questions ,please comment them below.

Tuesday, 24 October 2017

LYRICS OF LOOK WHAT YOU MADE ME DO

The lyrics of Look what you made me do song. Sing by Taylor swift. It's a nice song.
It's like a bold song,but it is not attract very much.

    LOOK WHAT YOU MADE ME DO
                                     by Taylor swift
I don't like your little games
don't like your tilted stage
The role you made me play
of the fool
No I don't like you
I don't like your perfect crime
How you laugh when you lie
you said the gun was mine
isn't cool
No I don't like you... ooh
But I got smarter I got harder
In the nick of time,
Honey I rose up from the dead
I do it all the time
 I got a list of names
And yours is in red, underlined
I check it once then I check it twice... ooh
ooh.. Look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do
Look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do
I don't like your kingdom keys
They once belonged to me
you asked me for a place to sleep
Locked me out
And threw a feast
The world moves on another day
another drama drama
But not for me not for me
All I think about is karma
And then the world moves on
But one things for sure
May be I got mine
But you'll all get yours
But I got smarter I got harder
In the nick of time,
Honey I rose up from the dead
I do it all the time
 I got a list of names
And types is in red, underlined
I check it once then I check it twice... ooh
ooh.. Look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do
ooh.. Look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do
I don't trust nobody and nobody trust me
Till be the actress starting on your bad dreams
I don't trust nobody and nobody trust me
Till be the actress starring on your bad dreams
I don't trust nobody and nobody trust me
Till be the actress starring on your bad dreams
I don't trust nobody and nobody trust me
Till be the actress starring on your bad dreams..
I'm sorry but the old Taylor can't come to the phone right now
why? ooh.. cause she's dead
ooh.. Look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do
ooh.. Look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do
ooh.. Look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do
ooh.. Look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do


In the above content is not satisfy, please comment on my comment box. If it useful share your friends
Share your smile!!!! spread your love!!!!

Saturday, 5 August 2017

Lose to wizarding world

LOST OF WIZARDING WORLD . .

Aug 3,2017...Minister of Magic  Cornelius Fudge is died at 91. His real name is Robert Hardy. His part of Harry Potter series is very big . He is doing great things in Wizarding world. At his age, Ministry of Magic make  brightest world.  He's also encouraging Harry to do great things. According to Harry Potter series, all characters are help. In that thing, Fudge doing many helps . we have lost one person in Wizarding world .He is a great actor.  So , we have to pray for his soul. 

J. K. ROWLING'S TWEET :

So very sad hear about Robert Hardy. He was  such a talented actor and everybody who worked with him on potter loved him . 

So,above content is not satisfying . please comment on my comment box . Thank u. . . .