Friday, 23 December 2016

DATE AND TIME IN C++

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<ctime>

using namespace std;

int main()
{
    time_t now = time(0);
    char *dt = ctime(&now);
   
cout<<"Today is : "<<dt<<endl;

}

1 comment:

  1. //PROGRAM TO PRINT SPIRAL MATRIX-
    #include
    using namespace std;

    int H=0,i,j,k=1,m[100][100];

    void help(char *ch,int l,int n,int p)
    {
    if(p==1)
    {
    for(j=1;j<=k/2;j++)
    {
    if(l)
    {
    ch[j]='|';
    l--;
    }
    else
    ch[j]=' ';
    }
    }
    else
    {
    for(j=n;j>k/2;j--)
    {
    if(l)
    {
    ch[j]='|';
    l--;
    }
    else
    ch[j]=' ';
    }
    }
    }

    int track(int m[][100],int n,int H)
    {
    if(n-H==0)
    return 1;
    else
    {
    if(H%2==0) //even
    {
    for(j=H/2;j<(n-H/2);j++)
    {
    m[H/2][j]=k;
    k++;
    }
    for(i=(H/2)+1;i<(n-H/2);i++)
    {
    m[i][n-(H/2)-1]=k;
    k++;
    }
    H++;
    track(m,n,H);
    }

    else //odd
    {
    for(j=n-((H+1)/2+1);j>=H/2;j--)
    {
    m[n-(H+1)/2][j]=k;
    k++;
    }
    for(i=n-(((H+1)/2)+1);i>=(H+1)/2;i--)
    {
    m[i][H/2]=k;
    k++;
    }
    H++;
    track(m,n,H);
    }
    }
    }

    void print(int m[][100],int n)
    {
    int l;
    char *ch;
    ch=new char[n];
    if(n%2==0)
    k=n;
    else
    k=n+1;
    cout<<"\t";
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n;j++)
    {
    if(i<=k/2)
    {
    cout<-2)
    {
    if(m[i-1][j-1]/10==0)
    cout<<"\t-->\t";
    else
    cout<<"\t-->\t";
    }
    else
    cout<<"\t \t";
    }
    else
    {
    cout<n&&i-j>0)
    cout<<"\t<--\t";
    else
    cout<<"\t \t";
    }
    }
    cout<<"\n\t";
    if(i<=k/2)
    {
    l=i;
    help(&(*ch),l-1,n,1);
    help(&(*ch),l,n,2);
    }
    else
    {
    l=n-i;
    help(&(*ch),l,n,1);
    help(&(*ch),l,n,2);
    }
    for(j=1;j<=n;j++)
    {
    if(ch[j]=='l')
    cout<>n;
    H=track(m,n,H);

    for(i=0;i<n;i++)
    {
    for(j=0;j<n;j++)
    {
    cout<<m[i][j]<<"\t";
    }
    cout<<"\n";
    }
    cout<<"\n\n";
    print(m,n);
    cout<<"\nCONTINUING:";
    H=0;k=1;
    }while(ch=='y'||ch=='Y');
    return 0;
    }

    ReplyDelete