Write a program in ‘C’ to add the given number of days to the current date and print the (final) resultant date. (for e.g. adding 12 days to 22/08/2005 will result in 03/09/2005) 10m Dec2005

By | June 4, 2014

Write a program in ‘C’ to add the given number of days to the current date and print the (final) resultant date. (for e.g. adding 12 days to 22/08/2005 will result in 03/09/2005)  10m Dec2005

    #include <time.h>
#include <stdio.h>
void  main()
{
struct tm date = {0} ;
time_t timer;
clrscr();
timer=time(NULL);
date = *gmtime( &timer ) ;
//printf(“%s”,asctime(localtime(&timer)));
printf(“%d/%d/%d\n”,date.tm_mday-1,date.tm_mon+1,date.tm_year+1900);
date.tm_year = date.tm_year;
date.tm_mon = date.tm_mon;
date.tm_mday = date.tm_mday + 12;
timer = mktime( &date ) ;
date = *gmtime( &timer ) ;
//printf(“%s”,asctime(localtime(&timer)));
printf(“%d/%d/%d\n”,date.tm_mday-1,date.tm_mon+1,date.tm_year+1900);
getch();
}

CODE : –

[codesyntax lang=”c” lines=”normal”]

#include <time.h>
#include <stdio.h>
void  main()
{
struct tm date = {0} ;
time_t timer;
clrscr();
timer=time(NULL);
date = *gmtime( &timer ) ;
//printf(“%s”,asctime(localtime(&timer)));
printf(“%d/%d/%d\n”,date.tm_mday-1,date.tm_mon+1,date.tm_year+1900);
date.tm_year = date.tm_year;
date.tm_mon = date.tm_mon;
date.tm_mday = date.tm_mday + 12;
timer = mktime( &date ) ;
date = *gmtime( &timer ) ;
//printf(“%s”,asctime(localtime(&timer)));
printf(“%d/%d/%d\n”,date.tm_mday-1,date.tm_mon+1,date.tm_year+1900);
getch();
}

[/codesyntax]

SCREEN SHOTS :-

C_program_Add_Days_to_Curr_Date

C_program_Add_Days_to_Curr_Date_Out

 

Q Write program in ‘C’ to find all Armstrong numbers in the range of 0 and 999. 10m Dec2005 

Solved program can be found on this link http://cssimplified.com/c-programming/a-c-program-to-find-all-armstrong-numbers-in-the-range-of-0-to-999

 

Leave a Reply