How to install gcc in ubuntu and run first C program

How to install gcc in ubuntu and run first C program

Here c program demonstrated is simple interest calculator.

Following are quick steps to install gcc

Go to terminal

login as root :

Sudo su

type command : (requires active Internet connection)

apt-get install gcc

Open gedit editor.

gedit

Type C Program & Save with .c extension. Download firstcprogram.c (114 downloads)

#include<stdio.h>
#include<stdlib.h>

int main()
{

	//program to calculate simple interest. formula is i=(p*n*r)/100;

	//p is principal amount
	//i is interest amount
	//r is rate of interest 
	//n is no. of years.


	double p,n,r,i;

	printf("\n\t ENTER PRINCIPAL AMOUNT : ");
	scanf("%lf",&p);

	printf("\n\t ENTER RATE OF INTEREST : ");
	scanf("%lf",&n);

	printf("\n\t ENTER TERMS : ");
	scanf("%lf",&r);


	i=(p*n*r)/100;

	printf("\n\t INTEREST CALCULATED IS %lf\n",i);


	return 0;
	
}

Compile C Program

gcc -o firstprogram firstcprogram.c

To run program

./firstprogram
output-firstprogram

output-firstprogram.c

This video shows simple steps to install gcc compiler on ubuntu 16.04 and run first C program for beginner.