$ cp ~sn/.bash_profile . $ source .bash_profile |
$ nano MyFirstProgram.c |
#include <stdio.h> int main() { printf("Hello world !\n"); return 0; } |
$ ls $ ls -lga MyFirstProgram.c $ cat MyFirstProgram.c |
$ gcc MyFirstProgram.c $ a.out |
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.
#include <stdio.h> int main() { /* this is a comment */ printf("Hello UTA !"); printf("\nHello World !\n"); return 0; } |
#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; } |
#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; } |
#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; } |
$ gcc -lm myprogram.c $ a.out |