CS13002 Programming and Data Structures

Spring semester

Getting started


The basic cycle


Some useful Unix commands

Here is a short list of useful commands that you can use from your shell (in addition to running emacs and compiling and running your program).


On-line help


Your first C program

#include <stdio.h>

                                                                                
main ()
{
                                                                                
   printf("****\n"); /* whatever is between quotes is printed verbatim */
   printf("*  *\n"); /* \n advances the cursor to the next line */
   printf("*  *\n");
   printf("****\n");
   printf("*  *\n");
   printf("*  *\n");
   printf("****\n");
}

Complete your edit-save-compile-debug-run cycle on this code. (Somebody of you may have experience with an integrated environment like TURBO C or Microsoft VC++. In Unix such an environment is generally missing. But that's not a big issue, as you will understand soon.)

Modify the above program to print a banner for "35".


The second C program

#include <stdio.h>


#define pi 3.14159



/* This program finds solutio to the simultaneous equations*/
/*a1.x + b1.y = c1 and a2.x + b2.y = c2 */

main ()


{
float x,y, a1,b1,c1,a2,b2,c2;

printf ("\nEnter a1 b1 c1 a2 b2 c2: ");
scanf ("%f%f%f%f%f%f", &a1, &b1,&c1,&a2,&b2,&c2);
printf ("%f %f %f %f %f %f", a1, b1, c1, a2, b2, c2);

x= (c1*b2-c2*b1)/(a1*b2-b1*a2);
y= (a1*c2-a2*c1)/(a1*b2-b1*a2);


printf ("\nValues of x and y are %f and %f\n",x,y);


}

Does it work for ALL situations ?


[Course home] [Lab home]