First c program

First c program

/* Program to print something. */

#include<stdio.h>

#include<conio.h>

main()

{

/* printing hello*/

printf(“hello”);

getch();

}

Description: this is our first c program which printing the hello.

In first line we have given the comments ‘/*………*/’. We can give comments like that, at any place in the program.

In the next two lines we are defining the header files which are in our c library and provides the help for input output in the program.

In next line we used ‘main()’ which tells the compiler from where execution of program will begins and it is an user defined function.

In next line we have the ‘{‘ which means block of a function is starting.

Then in next line we printed the hello. The ‘printf()’ is an inbuilt function. And we use ‘;’ which is used to terminate the line.

Then we have use ‘getch()’ function which is use to hold the screen till any button is pressed.

And again we used ‘}’ to close the ‘main()’ function.

Another simple program:

/*PROGRAM TO CALCULATE SIMPLE INTEREST*/

#include<stdio.h>

#include<conio.h>

void main()

{

float p,r,t,si;

clrscr();

printf(“Enter the principle amount: “);

scanf(“%f”,&p);

printf(“Enter the rate of interest: “);

scanf(“%f”,&r);

printf(“Enter the time period: “);

scanf(“%f”,&t);

si=(p*r*t)/100;

printf(“Simple interest is: %f”,si);

getch();

}

Posted in C

Leave a Reply

Your email address will not be published. Required fields are marked *