Show Menu
Cheatography

midsemester prep exam 2 prep Cheat Sheet (DRAFT) by

programs I completed so far

This is a draft cheat sheet. It is a work in progress and is not finished yet.

day of the week

 // I, Ebuka Chibueze certify this is my own work and I have not collaborated with anyone
 // 10/04/2014
#define _CRT_SECURE_NO_WARNINGS   
#include <stdio.h>
int main(int) 
{ 
 int m, d, y, daycode, numdays; //m->Month d->Day y->Year 
 printf("Enter date(mm dd yyyy):"); 
 scanf("%d %d %d", &m, &d, &y); 
 while(m!=0 && d!=0 && y!=0) 
 { 
 numdays = (((y-1)*365)+((y-1)/4)-((y-1)/100)+((y-1)/400)); //numdays is 
//the total number of days within the year plus the next year 
 
 
 
 
 switch(m) 
 { case 1: d =d; 
 break; 
 case 2: d=d+31; 
 break; 
 case 3: d=d+28+31; 
 break; 
 case 4: d=d+31+28+31; 
 break; 
 case 5: d=d+30+31+28+31; 
 break; 
 case 6: d=d+31+30+31+28+31; 
 break; 
 case 7: d=d+30+31+30+31+28+31; 
 break; 
 case 8: d=d+31+30+31+30+31+28+31; 
 break; 
 case 9: d=d+31+31+30+31+30+31+28+31; 
 break; 
 case 10: d=d+30+31+31+30+31+30+31+28+31; 
 break; 
 case 11: d=d+31+30+31+31+30+31+30+31+28+31; 
 break; 
 case 12: d=d+30+31+30+31+31+30+31+30+31+28+31; 
 break; 
 
 } 
 
 
 if (((!(y%4) && (y%100)) || !(y%400)) && m>=3) 
 { 
 d = d +1; 
 } 
 
 
 numdays = numdays+d; 
 daycode = numdays%7; 
 //If daycode is 0->Sunday 1->Monday 2->Tuesday 3->Wednesday 4->Thursday 5

 if (daycode == 0) 
 printf("Sunday\n"); 
 else if (daycode == 1) 
 printf("Monday\n");  
 else if (daycode == 2)
 printf("Tuesday\n"); 
 else if (daycode == 3) 
 printf("Wednesday\n"); 
 else if (daycode == 4) 
 printf("Thursday\n"); 
 else if (daycode == 5) 
 printf("Friday\n"); 
 else if (daycode == 6) 
 printf("Saturday\n"); 
 
 
 printf("Enter date(mm dd yyyy):"); 
 scanf("%d %d %d", &m, &d, &y); 
 } 
}
 

hypotenuse > function practice

#define_CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>

double hyp(double, double); // proto type must have semi colon
int main()
{
    double x,y,h;
    printf("  enter x and y ");
    scanf(" %lf %lf ", &x, &y);
    h = hyp(x,y);
    printf("hypotenuse is :%lf\n ", h);
}
 return 0;

double hyp( double a, double b)
{
    double sum, result;
    sum=aa +bb;
    result = sqrt(sum);
    return result;
}

links