7.2 Fibonacci Series7 Assignments7.1 Getting Started

7.1 Getting Started

7.1.1 Getting Started -- Programs

  1. hello.c
    
    /* Program to print "hello, world"                  */ 
    /* L Taber   October 13, 1992   PCC                 */
    /* Kernighan & Richie "The C Programming Language"  */ 
    /* Copyright 1978  page 6                           */
    
    #include <stdio.h> 
    
    main() 
    { 
    printf("hello, world\n"); 
    }
    
    When you run it is should look like this:
    hello, world
    
     
  2. limits.c
    /*H*****************************************
     * limits.c   
     * Louis Taber, PCC, Dec 14, 2000
     *******************************************/
    
    #include <limits.h>
    
    main()
    {
    printf( "Minimum and maximun values for"
            " various types.\n\n" );
    printf( "%d <= char <= %d\n", CHAR_MIN, CHAR_MAX );
    printf( "0 <= uchar <= %u\n", UCHAR_MAX );
    printf( "%d <= short <= %d\n", SHRT_MIN, SHRT_MAX );
    printf( "0 <= ushort <= %u\n", USHRT_MAX );
    printf( "%d <= int <= %d\n", INT_MIN, INT_MAX );
    printf( "0 <= uint <= %u\n", UINT_MAX );
    printf( "%ld <= long <= %ld\n", LONG_MIN, LONG_MAX );
    printf( "0 <= ulong <= %lu\n\n", ULONG_MAX );
     
    }
    
    When you run it is should look something like this:
    Minimum and maximun values for various types.
    
    -128 <= char <= 127
    0 <= uchar <= 255
    -32768 <= short <= 32767
    0 <= ushort <= 65535
    -2147483648 <= int <= 2147483647
    0 <= uint <= 4294967295
    -2147483648 <= long <= 2147483647
    0 <= ulong <= 4294967295
    
    
    Please note the limits of your compiler!
  3. modular program with math functions. Run the following 2 module program with a header. I compile it with the following command:
    gcc -o mod mod-main.c mod-sub.c -lm
    
    /*H******************************************************
     *   Program to check out development environment 
     * 
     * Louis Taber
     * December 5, 2000
     * CIS265
     *
     * mod-main.c
     *
     ********************************************************/
    
    #include <stdio.h>
    #include <math.h>
    #include "mod.h" 
    
    float sinandcos( float, float);
    int   iadd(int, int);
    
    int main(void)
    {
    int   a, b = CONSTANT_B, c = CONSTANT_C;
    float x, y = CONSTANT_Y, z = CONSTANT_Z;
    
    /* Print out header */
    
    printf("Your-name\n");
    printf("CIS 265 - Spring 2001 - Taber Lab - 4.1\n\n"); 
    
    /* Integer subroutine and constants */ 
    
    printf("b= %d, %08X    c= %d,  %0o\n", b, b, c, c);    
    a = iadd(b,c);
    printf("a = %07d\n\n",a);
    
    /* Floating point subroutine and constants */ 
    
    printf("y= %f, %18.12g\nz= %f, %18.12g\n\n", y, y, z, z);    
    x = sinandcos(y,z);
    printf("x=%+18.12lg\n", x);
    
    return 0;
    }
    
    
    and
    /*H******************************************************
     *   Program to check out development environment 
     * 
     * Louis Taber
     * December 5, 2000
     * CIS265
     *
     * mod-sub.c
     *
     ********************************************************/
    
    #include <math.h>
    
    int 
    iadd(int b, int c)
    {
    return b+c;
    }
    
    float
    sinandcos(float y, float z)
    {
    return sin( y ) + cos( z );
    }
    
    and
    /*H******************************************************
     *   Program to check out development environment 
     * 
     * Louis Taber
     * December 5, 2000
     * CIS265
     *
     * mod.h
     *
     ********************************************************/
    
    #define CONSTANT_B 12 
    #define CONSTANT_C 18
    #define CONSTANT_Y 1.1111111111111111111111
    #define CONSTANT_Z 2.2222222222222222222222
    
    
    My output looks like:
    Your-name
    CIS 265 - Spring 2001 - Taber Lab - 4.1
    
    b= 12, 0000000C    c= 18,  22
    a = 0000030
    
    y= 1.111111,      1.11111116409
    z= 2.222222,      2.22222232819
    
    x=    +0.28987121582
    

Mark the output of the multiple module program with:

Please turn your lab in to me, Louis Taber, during class, or slide it under the door of Santa Rita Building room A-115 (my office).


Instructor: Louis Taber, louis.taber.at.pima at gmail dot com (520) 206-6850
My web site in Cleveland, OH
The Pima Community College web site

7.2 Fibonacci Series7 Assignments7.1 Getting Started