How you can run a c program in Linux?

in Categories , , last updated October 16, 2007

Q. I’ve a c program and I’d like to run in Linux.

A. C program need to compile and run in Linux using cc or gcc command. When you invoke GCC (GNU C Compiler), it normally does preprocessing, compilation, assembly and linking for you. For example to compile hello.c program , type the following command:
cc -o hello hello.c
OR
gcc -o hello hello.c

It will compile and produced an exectuable file called hello. To run program type:
./hello

If else statement in C Program

in Categories , , last updated August 16, 2007

Q. Can you give me example for If else statement in C Program under Linux or TC?

A. C follows universal syntax for if..else. You can use any complier GNU Linux gcc or UNIX or old good TC.

if..else syntax

General if..else syntax is as follows:

if ( condition ) {
   expr_set1;
}
else  {
   expr_set2;
}

If given condition is TRUE, expr_set1 will get executed.
If given condition is FALSE (not TRUE), expr_set2 will get executed.

if..else example

Following example will find out large number from given input:

#include<stdio.h>
int main(){
        int x,y;
        printf("Enter value for x :");
        scanf("%d",&x);
        printf("Enter value for y :");
        scanf("%d",&y);
        if ( x > y ){
                printf("X is large number - %d\n",x);
        }
        else{
                printf("Y is large number - %d\n",y);
        }
        return 0;
}

How to see output of C program in Linux or UNIX

in Categories , , , , , , , last updated December 11, 2017

I am a new user of Linux operating system but not to C programming language. At my university we are using Turbo C compiler under DOS/Windows XP to write and compile C programs. Under Linux I wrote a small program called test.c. How do I compile and see the output of C program in a Linux when using Fedora Linux?