GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 75 of 203    Print  
hey anybody help me to write code for this program
wap which display year,month & day presents in a year for eg.
1. no. is 14 print 2 weeks
2. no is 90 print 3 months
3. no is 365 print 1 year
user can input any no

  
Total Answers and Comments: 3 Last Update: June 21, 2008     Asked by: avingle 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
March 22, 2006 04:21:47   #1  
rskusuma Member Since: March 2006   Contribution: 1    

RE: hey anybody help me to write code for this program...
#includevoid main(){ int n; int y m d; printf( enter a number ); scanf( d &n); printf( \n ); if (n/365 > 0) { printf( d Year(s) n/365); n n 365; } if (n/30 >0) { printf( 2d Month(s) n/30); n n 30; } if (n/7 >0) { printf( 3d week(s) n/7); n n 7; } if (n>0) { printf( 3d Day(s) n); }}OutPut:enter a number9 0 3 Month(s)
 
Is this answer useful? Yes | No
September 27, 2006 07:48:51   #2  
swetha76 Member Since: September 2006   Contribution: 2    

RE: hey anybody help me to write code for this program...

int rem_yr 0 yr 0 n rem_mon 0 mon 0 rem 0 wek 0;
printf( enter a numbern );
scanf( d &n);
if(n> 365)
{
yr n/365;
rem_yr n 365;
if(rem_yr> 30)
{
mon rem_yr/30;
rem_mon rem_yr 30;
}
if(rem_mon>7)
{
wek rem_mon/7;
rem rem_mon 7;
}

printf( d Years d Month d Weeks d days yr mon wek rem);
}
else if((n> 30)&&(n<365))
{
mon n/30;
rem_mon n 30;
if(rem_mon> 7)
{
wek rem_mon/7;
rem rem_mon 7;
printf( d Month d Weeks d days mon wek rem);
}
else
printf( d Month d Weeks d days mon wek rem_mon);

else
printf( d Month d Weeks d days mon wek rem_mon);
}
else if(n<30)
{
wek n/7;
rem n 7;

printf( d Weeks d days wek rem);
}
}


 
Is this answer useful? Yes | No
June 20, 2008 17:27:30   #3  
chiyuwang Member Since: June 2008   Contribution: 4    

RE: hey anybody help me to write code for this programwap which display year,month & day presents in a year for eg.1. no. is 14 print 2 weeks2. no is 90 print 3 months3. no is 365 print 1 yearuser can input any no

#include <iostream>

using namespace std;

void CalculateDate(const unsigned int _date);

int _tmain(int argc _TCHAR* argv[])
{
unsigned int date;
cout<<"Please input a number:"<<endl;
std::cin >> date;
CalculateDate(date);
return 0;
}

void CalculateDate(const unsigned int _date)
{
int iYear iMonth iDay iLeftDays;
iYear _date/365;
iLeftDays _date 365;
iMonth iLeftDays / 30;
iLeftDays iLeftDays 30;
iDay iLeftDays 30;

if( iYear ) cout<<"Year:"<<iYear<<endl;
if( iMonth ) cout<<"Month:"<<iMonth<<endl;
if( iDay ) cout<<"Day:"<<iDay<<endl;

return;
}

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape