LAB #1 (01/13, 1/15 or 1/17/2025)

Logging in omega

Your password won't echo.
To log off from omega, control-D or type exit or logoff.

Getting around Unix

Once you login to omega, try the following commands:

nano/your first C program

Assignment (due 01/22)

Compose, execute and run the following programs and figure out what they do. Then, write C programs following the instructions: A hint for each problem is provided. The same rule as homework submission applies.
  1. Prints three blank lines followed by "Hello World."
    Sample program:
    #include <stdio.h>
    int main()
    {
    /* this is a comment */
    printf("Hello UTA !");
    printf("\nHello World !\n");
    return 0;
    }
    
    \ n sends a new line.
  2. Reads two real numbers from the keyboard and prints their product.
    Sample program:
    #include <stdio.h>
    int main()
    {
    int a, b;  /* to declare that a and b are integer variables */
    printf("Enter two integer numbers separated by space =");
    scanf("%d %d", &a, &b); /* this is the way to read two integer numbers and assigned them to a and b */
    
    printf("The sum of the two numbers is %d.\n", a+b); /* %d is for integer format*/
    return 0;
    }
    
  3. Reads a real number and outputs its inverse. If 0 is read, writes a warning message and quit.
    Sample program:
    #include <stdio.h>
    int main()
    {
    float a;
    printf("Enter a number = ");scanf("%f", &a);
    
    if (a==0.0) printf("You entered 0.\n");
     else printf("You entered a number other than 0.\n");
    return 0;
    }
    
  4. Reads a real number, x, and outputs its sine, i.e. sin x. You need to use math.h and the -lm compile option.
    Sample program:
    #include <stdio.h>
    #include <math.h>
    int main()
    {
    float x;
    printf("Enter a number ="); scanf("%f", &x);
    printf("x= %f exp(x)=%f\n",x, exp(x));
    return 0;
    }
    
    Sample run (note the -lm option):
    $ gcc -lm myprogram.c
    $ a.out
    




File translated from TEX by TTH, version 4.03.
On 13 Jan 2025, 22:16.