Getting Started with "C"

 

#include<source_file.h>

 

A "source file" can be any file, with a name of any form, but is most commonly named with a ".h" extension and called a "header file"

 

If you want to include your own header file

then you can save it with ".h" and include it as

#include"source_file.h"

 

 

Now comes main()

 

main( )is a function. Every function has

a pair of parentheses( )associated with it.

main( )  is a collective name given to a set of statements.

 

main( )

{

statement 1 ;

statement 2 ;

statement 3;

}

printf("Hello World");          [for text]

printf("%d",a);                     [ for int]

      printf("%f",a);                  [ for float ]

printf("%c",a);                      [ for char]

scanf("%d",&a);                [ for int]

scanf("%f",&a);                   [ for float]

scanf("%c",c);                     [ for Char]

 

The C Character Set

 

Alphabets:

A, B, ....., Y, Z

a, b, ......, y, z

 

Digits:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9

 

Special symbols:

~ ‘ ! @ # % ^ & * ( ) _ - + = | \ { }

[ ] : ; " ' < > , . ? /

C Constants
 

1.Primary Constants:

         Integer Constant

      Real Constant

Character

 

 

2.Secondary Constants:

Array

Pointer

Structure

Union

Enum

 

 

 

tc

.

Key Words:

auto,double ,int,struct

break,else,long,switch

case,enum,register

typedef,char,extern

return,union,const

float,short,unsigned,

continue,for,signed,

void,default,goto

sizeof,volatile,do

if,static,while

Arithmetic Operators and it's priority:

*,/,% (mutiplication,division,modulus)

+,- (add,subtract)

= (assign)

 

Write a program to find area of circle?

#include<stdio.h>

 void main(){
   
 int radius;

float area,pi;

pi=3.14;

radius=2;

 area=pi*radius*radius;

printf("Area of circle =%f",area);

}

Write a program to find value of "k"

where  k = ( (a * b ) + c ) ( 2.5 * a + b )

and

a=3,

b=5.5,

c=  -3,

?

#include<stdio.h>

Void main(){

int a,c;

float b,k;

a=3;

b=5.5;

C=-3;

k = ( (a * b ) + c )*( 2.5 * a + b );

printf("value of k = %f",k);

}

scanf()

is for taking input from user.

int a;

 

now take value from user to assign to

a

then

scanf("%d",&a);

 

%d    for int

%f   for float

%c   for char

Write a program to find area of rectangle by taking length and breadth from user ?

 

Hint:use   "scanf()"

#include<stdio.h>

 void main(){
   
 int length,breadth,area;


scanf("%d",&length);

scanf("%d",&breadth);

 area=length*breadth;

printf("Area of rectangle =%d",area);

}
#include<stdio.h>

 void main(){
   
 int length,breadth,area;


scanf("%d%d",&length,&breadth);

 area=length*breadth;

printf("Area of rectangle =%d",area);

}

The Decision

Control Structure

 

Logical operators:

If

else

 

if(con==true){

statement1;

}

else{

statement 2;

}

 

 

 

Write a program to check whether a user input number is equal to two(2) or not?

#include<stdio.h>

void main(){

int a;

scanf("%d",&a);

if(a==2){
printf("a is equal to 2");
}

else{
printf("a is not equal to 2");
}

}

Find Error?

include<stdio.h>

Void main(){

int a,b,c,k;


 scanf("%d",a);


c=5.3;

scanf("%d",&b);

k=(a*b)(a*c);

printf("%f",k);

}
Made with Slides.com