Skip to content

Instantly share code, notes, and snippets.

@s3f
Created December 29, 2016 22:45
Show Gist options
  • Save s3f/f33eb540bd2b922adc3b08253762b07c to your computer and use it in GitHub Desktop.
Save s3f/f33eb540bd2b922adc3b08253762b07c to your computer and use it in GitHub Desktop.
Chapter 7- Using #include and #define created by s3f - https://repl.it/Easm/2
// The purpose of the warmup code below is to output is to practice displaying variables
/*
#include <stdio.h>
int main()
{
int a = 125, b = 12345;
long ax = 1234567890;
short s = 4043;
float x = 2.13459;
double dx = 1.1415927;
char c = "W";
unsigned long ux = 2541567890;
printf("a + c = %d\n", a + c);
printf("x + c = %f\n", x + c);
printf("dx + x = %f\n", dx + x);
printf("((int) dx) + ax = %ld\n", ((int) dx) + ax);
printf("a + x = %f\n", a + x);
printf("s + b = %d\n", s + b);
printf("ax + b = %ld\n", ax + b);
printf("s + c = %hd\n", s + c);
printf("ax + c = %ld\n", ax + c);
printf("ax + ux = %lu\n", ax + ux);
return 0;
}
*/
/* The output of the above code is
a + c = 65
x + c = -57.865410
dx + x = 3.276183
((int) dx) + ax = 1234567891
a + x = 127.134590
s + b = 16388
ax + b = 1234580235
s + c = 3983
ax + c = 1234567830
ax + ux = 3776135780
*/
// This practice program below lists 3 kids and their school supply needs, as well as the cost to buy the supplies
// This practice program below lists 3 kids and their school supply needs, as well as the cost to buy the supplies
#include <stdio.h>
#include <string.h>
#define KIDS 3
#define FAMILY "The Peytons"
#define MORGAGE_RATE 5.15
main()
{
int age;
char childname[14] = "Thomas";
printf("\n%s have %d kids.\n", FAMILY, KIDS);
age = 11;
printf("The oldest, %s, is %d.\n", childname, age);
strcpy(childname, "Christopher");
age = 6;
printf("The middle boy, %s, is %d.\n", childname, age);
strcpy(childname, "Christopher");
age = 3;
strcpy(childname, "Benjamin");
printf("The youngest, %s, is %d.\n", childname, age);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment