Write a program to display today\'s date in binary, in this format: Today\'s dat
ID: 3625281 • Letter: W
Question
Write a program to display today's date in binary, in this format:Today's date is:
011
0100
01101
Press any key to continue . . .
The three lines represent, respectively, the day of the week (1-7 for Monday-Sunday), the month of the year (1-12 for January-December), and the day of the month (1-31), all displayed in binary. (The above date is Wednesday, April 13.) You can obtain this information by creating and intializing a pointer to a struct tm, defined in time.h
This is what I have so far not much..not sure how to convert numbers for todays date to binary form. I was thinking that I can divide each number by 2 then take modulus and that would give me the binary form of the number.
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
struct time
{
int tm_sec; /* Seconds: 0-59 (K&R says 0-61?) */
int tm_min; /* Minutes: 0-59 */
int tm_hour; /* Hours since midnight: 0-23 */
int tm_mday; /* Day of the month: 1-31 */
int tm_mon; /* Months *since* January: 0-11 */
int tm_year; /* Years since 1900 */
int tm_wday; /* Days since Sunday (0-6) */
int tm_yday; /* Days since Jan. 1: 0-365 */
int tm_isdst; /* +1 Daylight Savings Time, 0 No DST,
-1 don't know */
};
main ()
(
time_t t = time(NULL);
struct tm *st = localtime(&t);
Explanation / Answer
please rate - thanks
here is a complete program to convert a decimal number to binary
what you need is in red
#include <conio.h>
#include <stdio.h>
int main()
{int num,answer;
printf("Enter the number to be converted into binary: ");
scanf("%d",&num);
printf("%d in binary is: ",num);
answer=tobinary(num);
printf("%d ",answer);
getch();
return 0;
}
int tobinary(int num)
{int digit,answer=0,power=1;
while (num!=0)
{
digit=num%2;
answer=answer+digit*power;
power*=10;
num=num/2;
}
return answer;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.