Hello world program in c

C programing language tutorial #2


Hello world program in c
Image source – google |image by-  medium.com


This is the 2 part of c programing language tutorial if you don’t watch the first part of this series then click here.

In this 2 part, we learn first ex. program of the c programing.

Hello world program in c

Step1: in sublime text editor click on a file and then select new file.

In turbo c++ compiler go in file and then select new.

Step2: write the below program in your compiler

 

#include  <stdio.h>         

Void main()

{

Printf(“hello world”);

}

 

Step3: after writing this above program if you are using sublime text editor  then  please use online c language compiler  due the sublime text editor is not for beginners and the syntax are also different.

To go on online compiler click hear

In this online compiler, you can easily find the run button after writhing above program just click on run and you can see your first output of first program.

Explanation of program:

In this program the first line is #include <stdio.h>  the c language has many library’s so if we want to use them we need to include them in program.

So to include this library’s we use #include then the stdio.h (standard input-output)is a library which we need to use in every program of c program so this #include <stdio.h> is a common In every program of the c language.

 Line no 2: void main()

In this the main show that the program is started from here and void  is a syntax of main you can also use int main() at the place of void main() but to use int main() you need to add return(0); at the end of program.

Ex.

#include  <stdio.h>         

int main()

{

Printf(“hello world”);

return 0 ;

}

Line3:

Printf(“hello world”);

So the printf is a keyword which is used to print anything on output screen so you can write anything at place of hello world.

So this is all for this tutorial your work to do is print your name at the place of hello world.

Symbol

Meaning

%d

Decimal number 

/n

Newline

int

Integer number

%f

Float number

 

Scanf:

The scarf is a keyword if you want to enter anything on output screen by using keyboard then you need to use this keyword to use this keyword you need to follow syntax of this keyword.

Syntax of scanf:

Scanf(“%data type of number”, & character );

Ex. sanf(“%d”, &b);

So in this, the %d=data type and “b” is a character scanf is use with print every time

Ex.

Int a;

Printf(“Enter number of pens:”);

Scanf(“%d”&a);

Output:

Enter number of pens:

In c program, if you want to use any character, or integer you need to define them after main section as shown in above example ‘a’ is defined as an integer.

 

Some basic practical of c programming language.  

(1)   To find area and perimeter of rectangle

#include <stdio.h>

#include <conio.h>

Void main()

{

Int L,B,A,P;

Printf(“enter length”);

Scanf(“%d”,&L);

Printf(“enter width \n”);

Scanf(“%d”,&B);

A=L*B;

P=2*(l+b);

Printf(“Area=%d\n”,A);

Printf(“Perimeter=%d”,P);

getch();

}

Explanation of program:

 Int L,B,A,P;

Hear we defined that we use L, B, A, P as an integer in this program.

Printf(“enter length”);

Scanf(“%d”,&L);

To find the area and perimeter of a rectangle we need the length and width of a rectangle so in this line we are requesting to a user that they enter length and to enter anything on output screen we need to use scanf.

A=L*B;

P=2*(l+b);

In this line, we use the formula of area and perimeter to find them and we save them in int A and int P.

Printf(“Area=%d\n”,A);

Printf(“Perimeter=%d”,P);

In this line, we print the area and perimeter of a rectangle on output screen which is stored in A and P.

getch();

this line shows that the program is end here.

(2)           TO find area and volume of cylinder

#include <stdio.h>

#include <conio.h>

Void main()

{

float r,h,a,v;

printf (“enter radius\n”);

scanf(“%f”,&r);

printf(“enter  height\n”);

scanf(“%f”,&h);

a=2*3.14*h;

v=3.14*r*r*h;

printf(“the area of cylinder %f\n”,a);

printf(“the volume of cylinder is %f\n”,v);

getch();

}

Output:

Enter radius:10

Enter height:10

The area of a cylinder is 628

 The volume of cylinder is 3140

This program is also same as 1 basic a program so the description is same if you have any problem then contact us.

    Thanks for reading.

 


Share This Article:

, ,

CONVERSATION

0 comentários :

Post a Comment

pleas do not enter any spam link in the comment box.