Basics

Clean Function Example

/*  File:  CleanFunctionExample.c
  By:  Christopher Manloloyo  
*/

/*  This Program is a function variation of Variables.c   */

float print_then_add(int x, float y);
main()
{  
    // declare variables
    int i_am_an_integer;
    char i_am_a_char;
    float i_am_a_float;
    double i_am_a_double;
    float sum;

    // initialize variables
    i_am_an_integer = 11;
    i_am_a_char = 'c';
    i_am_a_float = 1.23;
    i_am_a_double = 1.23;

    // use variables
    printf("This is an integer: %i \n", i_am_an_integer);
    printf("This is an char: %c \n", i_am_a_char);
    printf("This is an float: %2.3f \n", i_am_a_float);
    printf("This is an double: %f \n", i_am_a_double);
    
    //Function Call
    sum = print_then_add(i_am_an_integer, i_am_a_float);
    /* 
    sum = print_then add(i_am_an_integer, (float)i_am_an_integer     + print_then add((integer)i_am_a_float, i_am_a_float           
    */
     printf("The sum of the integer and float is: %3.5f \n", sum);
}

float print_then_add(int x, float y)
{      
    //float sumOfNum;
     // print the values for x and y
     printf("The value of x in the function is : %i \n", x);
     printf("The value of y in the function is : %f\n", y);
      // Return  The Sum
     
     return (x+y);
    // Alternatively, we could write the code in comments below.
    //sumOfNum = x+y;
    //return sumOfNum;
}

hello.c

/*  File: hello.c
  By: Christopher Manloloyo
  login: manloloy
  Date: 20 August 2017
  Mod: 20 August 2017
*/

#include <stdio.h> 

main() 
{
    printf("Hello World\n");
    printf("Bye World\n");
}

hello.clean.c

main() 
{
    printf("Hello World\n");
    printf("Bye World\n");
}

template.c

/*  File: template.c
  By: Christopher Manloloyo
  login: manloloy
  Date: 
  Mod: 
*/

#include <stdio.h> 

main() //this portion is the header
{

}

tfdf.h

/*  File:  tfdef.h
  By:  Christopher Manloloyo
  login:  manloloy
        Date:
        Mod :
*/


/*  Header file defining true and false macros   */

#define FALSE 0
#define TRUE  1

variables.c

#include <stdio.h>

main() {
    // declare variables
    int i_am_an_integer;
    char i_am_a_char;
    float i_am_a_float;
    double i_am_a_double;

    // initialize variables
    i_am_an_integer = 11;
    i_am_a_char = 'c';
    i_am_a_float = 1.23;
    i_am_a_double = 1.23;

    // use variables
    printf("This is an integer: %i \n", i_am_an_integer);
    printf("This is an char: %c \n", i_am_a_char);
    printf("This is an float: %2.3f \n", i_am_a_float);
    printf("This is an double: %f \n", i_am_a_double);
}