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
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]
Alphabets:
A, B, ....., Y, Z
a, b, ......, y, z
Digits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Special symbols:
~ ‘ ! @ # % ^ & * ( ) _ - + = | \ { }
[ ] : ; " ' < > , . ? /
1.Primary Constants:
Integer Constant
Real Constant
Character
2.Secondary Constants:
Array
Pointer
Structure
Union
Enum
tc
.
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
*,/,% (mutiplication,division,modulus)
+,- (add,subtract)
= (assign)
#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
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);
}
If
else
if(con==true){
statement1;
}
else{
statement 2;
}
#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");
}
}
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);
}