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 : -

  1. #include <time.h>
  2. #include <stdio.h>
  3. void  main()
  4. {
  5. struct tm date = {0} ;
  6. time_t timer;
  7. clrscr();
  8. timer=time(NULL);
  9. date = *gmtime( &timer ) ;
  10. //printf("%s",asctime(localtime(&timer)));
  11. printf("%d/%d/%d\n",date.tm_mday-1,date.tm_mon+1,date.tm_year+1900);
  12. date.tm_year = date.tm_year;
  13. date.tm_mon = date.tm_mon;
  14. date.tm_mday = date.tm_mday + 12;
  15. timer = mktime( &date ) ;
  16. date = *gmtime( &timer ) ;
  17. //printf("%s",asctime(localtime(&timer)));
  18. printf("%d/%d/%d\n",date.tm_mday-1,date.tm_mon+1,date.tm_year+1900);
  19. getch();
  20. }

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