answersLogoWhite

0

What else can I help you with?

Continue Learning about Engineering

What did Jose N Rodriguez invented?

invented methods of controlling hansen's disease commonly known as leprosy


How do you wrte aC program to print calendar?

#include<stdio.h> #define TRUE 1 #define FALSE 0 int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; char *months[]= { " ", "\n\n\nJanuary", "\n\n\nFebruary", "\n\n\nMarch", "\n\n\nApril", "\n\n\nMay", "\n\n\nJune", "\n\n\nJuly", "\n\n\nAugust", "\n\n\nSeptember", "\n\n\nOctober", "\n\n\nNovember", "\n\n\nDecember" }; int inputyear(void) { int year; printf("Please enter a year (example: 1999) : "); scanf("%d", &year); return year; } int determinedaycode(int year) { int daycode; int d1, d2, d3; d1 = (year - 1.)/ 4.0; d2 = (year - 1.)/ 100.; d3 = (year - 1.)/ 400.; daycode = (year + d1 - d2 + d3) %7; return daycode; } int determineleapyear(int year) { if(year% 4 FALSE) { days_in_month[2] = 29; return TRUE; } else { days_in_month[2] = 28; return FALSE; } } void calendar(int year, int daycode) { int month, day; for ( month = 1; month <= 12; month++ ) { printf("%s", months[month]); printf("\n\nSun Mon Tue Wed Thu Fri Sat\n" ); // Correct the position for the first date for ( day = 1; day <= 1 + daycode * 5; day++ ) { printf(" "); } // Print all the dates for one month for ( day = 1; day <= days_in_month[month]; day++ ) { printf("%2d", day ); // Is day before Sat? Else start next line Sun. if ( ( day + daycode ) % 7 > 0 ) printf(" " ); else printf("\n " ); } // Set position for next month daycode = ( daycode + days_in_month[month] ) % 7; } } int main(void) { int year, daycode, leapyear; year = inputyear(); daycode = determinedaycode(year); determineleapyear(year); calendar(year, daycode); printf("\n"); }


What is the program for snake and ladder game in c plus plus?

#include<iostream> #include<array> #include<string> #include<random> #include<ctime> using player_t = std::array<unsigned, 2>; using pair_t = std::pair<unsigned, unsigned>; using snake_t = std::array<pair_t, 10>; using ladder_t = std::array<std::pair<unsigned, unsigned>, 9>; const std::string player (const bool human) { return std::string {human ? "You" : "I"}; } int main() { std::default_random_engine generator ((unsigned) time (0)); std::uniform_int_distribution<unsigned> distribution (1, 6); player_t players = {0,0}; const snake_t snakes = {pair_t {98,78}, {95,75}, {93,73}, {87,24}, {64,60}, {62,19}, {56,53}, {49,11}, {47,26}, {16,6}}; const ladder_t ladders = {pair_t {1,38}, {4,14}, {9,31}, {21,42}, {28,84}, {36,44}, {51,67}, {71,91}, {80,100}}; std::cout << "Snakes and Ladders\n"; std::cout << "==================\n\n"; std::cout << "First to land exactly on square 100 wins.\n"; bool human = (distribution (generator) % 2)==0 ? true : false; std::cout << player (human) << " will go first.\n\n"; for (;;human=!human) { std::cout << (human ? "Your" : "My") << " turn:\n"; unsigned dice = distribution (generator); std::cout << '\t' << player (human) << " rolled a " << dice << ".\n"; unsigned& pos = players [human?0:1]; if (pos+dice>100) { std::cout << '\t' << player (human) << " cannot move"; goto next_player; } pos+=dice; std::cout << '\t' << player (human) << " landed on square " << pos; for (auto snake : snakes) { if (snake.first==pos) { pos = snake.second; std::cout << " with a snake; return to square " << pos; goto next_player; } } for (auto ladder : ladders) { if (ladder.first==pos) { pos = ladder.second; std::cout << " with a ladder; climb to square " << pos; goto next_player; } } next_player: std::cout << ".\n\n"; if (pos==100) { std::cout << player (human) << " won!\n"; break; } } }


What inventions were invented in the 1880's?

1880 Invented a magnetic ore separator. Invented and installed the first life-sized electric railway for handling freight and passengers at Menlo Park, N. J.


According to the Gregorian calendar it was Monday on the date 01 01 1900 if any year is input through the keyboard write a c program to find your what is the day on 1st January of this year?

#include <stdio.h> int main () { int year,days,d; printf("year?"); scanf("%d",&year); days = 365*year + (year-1)/4 - (year-1)/100 + (year-1)/400 ; d=days%7;//to find which day of week if(d==1) printf("\n\n\tmonday"); else if(d==2) printf("\n\n\ttuesday"); else if(d==3) printf("\n\n\twednesday"); else if(d==4) printf("\n\n\tthursday"); else if(d==5) printf("\n\n\tfriday"); else if(d==6) printf("\n\n\tsaturday"); else if(d==0) printf("\n\n\tsunday"); return(0); }