The greatest mistake you can make in life is to be continually fearing you will make one

Sunday, 21 November 2010

C programs

  1. Write a c program to get the system time and date?
    Solution:
    #include<stdio.h>
    #include<time.h>
    int main()
    {
        char *date;
        time_t timer;
        timer=time(NULL);
        date=asctime(localtime(&timer));
        printf("date:%s",date);
        return;
    }
    Output:
    ./a.out
    date:Fri Nov 19 18:30:21 2010
  2. Write a c program to reverse a line of text (or) reverse a string without using string fucnctions
    #include<stdio.h>
    void display(void);
    int main()
    {
        printf("Enter the line of text\n" );
        display();
        return 0;
    }
    void display()
    {
        char c;
        if((c=getchar())!='\n')
            display();
        putchar(c);
        return;
    }
    sunitha@sunitha-laptop:~/cpgm$ ./a.out
    Enter the line of text
    Welcome to c World

    dlroW c ot emocleW

No comments:

Post a Comment