Header Graphic

பொன்மொழிகள்!     

 

 

 C hello world example  

#include <stdio.h>
main( )
{
printf("Hello world\n");
}
#include <stdio.h>
#include<conio.h>
main()
{
clrscr();
printf("Hello world\n");
getch();
}

 

C program print integer  

#include <stdio.h>
#include<conio.h>
main()
{
int a;
clrscr();
printf("Enter an integer\n");
scanf("%d", &a);
printf("Integer that you have entered is %d\n", a);
getch();
}

 

 

 

 

C program to add two numbers  

#include<stdio.h>
#include<conio.h>
main()
{
int a, b, c;
clrscr( );
printf("Enter two numbers to add\n");
scanf("%d%d",&a,&b);
c = a + b;
printf("Sum of entered numbers = %d\n",c);
getch( );
}      

c program print character  

 

#include<stdio.h> 

#include<conio.h> 

 main( ) 

char k='z'; /*initialization*/ 

clrscr( ); 

printf("the character value is:%d",k); 

printf("the character value is:%c",k); 

 

getch( ); 

Write A Program To Display Employee Details 

 

#include<stdio.h> 

#include<conio.h> 

main( ) 

int no; 

char n[30];   //character array (string) 

float ba,hra,lic,pf; 

double net,gr,tot; 

char d; 

clrscr(); 

printf("Enter Employee Number:"); 

scanf("%d",&no); 

 

printf("Enter Employee Name:"); 

scanf("%s",&n); 

printf("Enter Basic Salary:"); 

scanf("%f",&ba); 

printf("Enter HRA:"); 

scanf("%f",&hra); 

printf("Enter LIC:"); 

scanf("%f",&lic); 

 

fflush(stdin); 

 

printf("Enter Department Code:"); 

scanf("%c",&d); 

 

pf=ba*0.9; 

tot=ba+hra+lic+pf; 

gr=lic+pf; 

net=tot-gr; 

 

printf("\n----------------------------\n"); 

printf("       EMPLOYEE DETAILS        \n"); 

printf("\n----------------------------\n"); 

printf("Employee Number=%d\n",no); 

printf("Employee Name=%s\n",n); 

printf("Department Code=%c\n",d); 

printf("Basic Salary=%f\n",ba); 

printf("HRA=%f\n",hra); 

printf("LIC=%f\n",lic); 

printf("PF=%f\n",pf); 

printf("Total Salary=%lf\n",tot); 

printf("Gross Salary=%lf\n",gr); 

printf("\n***********************\n"); 

printf("Net Salary=%lf\n",net); 

printf("\n***********************\n"); 

getch(); 

ASSIGNMENTS

1. C program to perform addition, subtraction, multiplication and division 

 

#include <stdio.h>
#include<conio.h>
main()
{
int first, second, add, subtract, multiply;
float divide;
clrscr();
printf("Enter two integers\n");
scanf("%d%d", &first, &second);
add      = first + second;
subtract = first - second;
multiply = first * second;
divide   = first / (float)second;  //typecasting
printf("Sum = %d\n",add);
printf("Difference = %d\n",subtract);
printf("Multiplication = %d\n",multiply);
printf("Division = %0.2f\n",divide);
getch();
}

 

2. WRITE A PROGRAM TO FIND AREA AND CIRCUMFERENCE OF CIRCLE 

 

#include<stdio.h> 

#include<conio.h> 

main( ) 

int radius; 

float area,circum; 

clrscr(); 

printf("radius="); 

scanf("%d",&radius); 

area=3.14*radius*radius; 

circum=2*3.14*radius; 

printf("area=%f\n",area); 

printf("circumference=%f",circum); 

getch(); 

 

3. write a program to display student details 

#include<stdio.h> 

#include<conio.h> 

main() 

int enrollno,tam,eng,math,sci,soc,total; 

char name[20]; 

float avg; 

clrscr(); 

printf("enter enrollno:"); 

scanf("%d",&enrollno); 

printf("enter name:\n"); 

scanf("%s",&name); 

printf("tamil mark:"); 

scanf("%d",&tam); 

printf("english mark:"); 

scanf("%d",&eng); 

printf("maths mark:"); 

scanf("%d",&math); 

printf("science mark:"); 

scanf("%d",&sci); 

printf("social mark:"); 

scanf("%d",&soc); 

total=tam+eng+math+sci+soc; 

printf("total=%d\n",total); 

avg=(float)total/5;/*type casting*/ 

/*avg=total/5;*/ 

printf("average:%0.2f",avg); 

getch(); 

 

 

/*operators 

1.arithmetic operators 

*/ 

 

#include<stdio.h> 

#include<conio.h> 

main( ) 

int a=10,b=20; 

clrscr(); 

printf("addition=%d\n",a+b); 

printf("subtraction=%d\n",a-b); 

printf("division=%d\n",b/a); 

printf("multiplication=%d\n",a*b); 

printf("modulus=%d\n",b%a); 

printf("modulus=%d\n",a%b); 

getch(); 

 

/*relational operator*/ 

 

#include<stdio.h> 

#include<conio.h> 

 

main( ) 

int a=10,b=5,c=5; 

clrscr(); 

printf("%d\n",a>b); 

printf("%d\n",b<a); 

printf("%d\n",a>=b); 

printf("%d\n",b<=c); 

printf("%d\n",c==b); 

printf("%d\n",a!=b); 

getch(); 

 

Logical operator 

 

#include<stdio.h> 

#include<conio.h> 

main( ) 

int a=10,b=5,c=3; 

clrscr(); 

printf("%d\n",(a>b)&&(a>c)); 

printf("%d\n",(b>a)&&(b>c)); 

printf("%d\n",(b>a)||(b>c)); 

printf("%d\n",(c>a)||(c>b)); 

printf("%d\n",!((c>a)||(c>b))); 

getch(); 

 

Conditional operator or ternary operator 

 

/*   ?: is a ternary operator  */ 

Syntax: 

 (condition) ? True : False 

 

#include<stdio.h> 

#include<conio.h> 

main( ) 

int a=50,b=10; 

clrscr(); 

printf("%d",(a<b)?a:b); 

getch( ); 

 

Increment and decrement operator 

 

#include<stdio.h> 

#include<conio.h> 

main( ) 

int a=5; 

clrscr( ); 

printf("a=%d\n",++a); 

printf("a=%d\n",a); 

printf("a=%d\n",a++); 

printf("a=%d\n",a); 

printf("a=%d\n",--a); 

printf("a=%d\n",a); 

printf("a=%d\n",a--); 

printf("a=%d\n",a); 

getch(); 

 

condition statement 

if is a condition statement 

 

syntax:- 

if(condition) 

statement 

 

EXAMPLE : 

 

#include<stdio.h> 

#include<conio.h> 

main() 

int a; 

clrscr(); 

printf("enter a value:"); 

scanf("%d",&a); 

if(a>0) 

printf("a is positive"); 

if(a<0) 

printf("a is negative"); 

getch(); 

 

if ..else statement 

syntax:- 

if(condition) 

statement 

else 

statement 

 

 

 

#include<stdio.h> 

#include<conio.h> 

main() 

int a; 

clrscr(); 

printf("enter a value:"); 

scanf("%d",&a); 

if(a>0) 

printf("a is positive"); 

else 

printf("a is negative"); 

getch(); 

ASSIGNMENT 

 

This program is used to check two numbers and find the given number is big 

 

#include<stdio.h> 

#include<conio.h> 

main() 

int num1,num2; 

clrscr(); 

printf("num1="); 

scanf("%d",&num1); 

printf("num2="); 

scanf("%d",&num2); 

if(num1>num2) 

printf("%d Num1 is big:",num1); 

else 

printf("%d Num2 is big:",num2); 

getch(); 

 

if ..else if statement 

syntax:- 

if(condition) 

statement 

else if(condition) 

statement 

} 

 

ASSIGNMENT 

 

This program is used to check two numbers and find the given number is big 

 

#include<stdio.h> 

#include<conio.h> 

main( ) 

int num1,num2; 

clrscr( ); 

printf("num1="); 

scanf("%d",&num1); 

printf("num2="); 

scanf("%d",&num2); 

if(num1>num2) 

printf("%d is big",num1); 

else if(num1<num2) 

printf("%d is big",num2); 

else 

printf("equal"); 

getch( ); 

 

write a program to compare three numbers and find the given number is big 

 

 

main( ) 

int num1,num2,num3; 

clrscr( ); 

printf("Enter num1 , num2 and num3: "); 

scanf("%d %d %d",&num1,&num2,&num3); 

if(num1>num2 && num1>num3) 

printf("num1 is big"); 

else if(num2>num1 && num2>num3) 

printf("num2 is big"); 

else if(num3>num1 && num3>num2) 

printf("num3 is big"); 

else 

printf("all numbers are equal"); 

getch( ); 

 

ASSIGNMENT 

 

/*write a program to find the given year is leap or not*/ 

#include<stdio.h> 

#include<conio.h> 

main( ) 

int  year; 

clrscr(); 

printf("year="); 

scanf("%d",&year); 

if (year % 4 ==0) 

printf("leap  year"); 

else 

printf("not leap  year"); 

getch( ); 

 

ASCII CODE :  American Standard Code for Information and Interchange 

 

ASCII CODE TABLE 

Upper Case 

Lower Case 

Character 

Code 

Character 

Code 

65 

97 

66 

98 

67 

99 

68 

100 

69 

101 

70 

102 

71 

103 

72 

104 

73 

105 

74 

106 

75 

107 

76 

108 

77 

109 

78 

110 

79 

111 

80 

112 

81 

113 

82 

114 

83 

115 

84 

116 

85 

117 

86 

118 

87 

119 

88 

120 

89 

121 

90 

122 

 

 

/*write a program to check the given character is vowel or not*/ 

 

main( ) 

char k; 

clrscr( ); 

printf("k="); 

scanf("%c",&k); 

if(k=='a' || k=='e' ||k=='i' || k=='o' || k=='u' || k=='A' || k=='E' || k=='U' || k=='I' || k=='O') 

printf("vowel"); 

else 

printf("not vowel"); 

getch(); 

 

/*nested if statement*/ 

A  if statement contain another if statement is known as nested if statement. 

 

syntax:- 

======== 

if(condition) 

if(condition) 

statement 

else 

statement 

else 

statement 

 

#include<stdio.h> 

#include<conio.h> 

main( ) 

int a; 

clrscr(); 

printf("a="); 

scanf("%d",&a); 

if(!(a==0)) 

if(a>0) 

printf("positive"); 

else if(a<0) 

printf("negative"); 

else 

printf("enter a nonzero value:"); 

getch(); 

 

/*switch case statement 

==================*/ 

syntax 

 

switch(expression) 

case <expression>: 

statement; 

break; 

case <expression>: 

statement; 

break;       

case <expression>: 

statement; 

break; 

default: 

statement; 

break; 

 

 

 

 

 

#include<stdio.h> 

#include<conio.h> 

main() 

char k; 

clrscr(); 

printf("k="); 

scanf("%c",&k); 

switch(k) 

case 'a': 

printf("apperentice staff"); 

break; 

case 'p': 

printf("permanenet staff"); 

break; 

case 't': 

printf("temproary staff"); 

break; 

default: 

printf("enter a,p,t only"); 

getch(); 

 

/*switch case statement 

==================*/ 

#include<stdio.h> 

#include<conio.h> 

main() 

int a; 

clrscr(); 

printf("a="); 

scanf("%d",&a); 

switch(a) 

case 1: 

printf("one"); 

break; 

case 2: 

printf("two"); 

break; 

case 3: 

printf("three"); 

break; 

default: 

printf("enter 1,2,3 only"); 

getch(); 

 

/*goto statement 

//============== 

//it is a jumping statement or unconditional control statement*/ 

 

 

SYNTAX: 

 goto   labelname; 

 

label  name - any name 

 

create label 

 

labelname: 

 

ex: 

 

WCC:     //label name 

 

goto WCC; 

 

#include<stdio.h> 

#include<conio.h> 

main() 

int a; 

clrscr(); 

 

process:   //label name 

printf("a="); 

scanf("%d",&a); 

 

if(a>0) 

printf("correct"); 

//goto process;   call   label  or  goto    label 

getch(); 

 

ASSIGNMENT 

/*goto statement 

==============*/ 

#include<stdio.h> 

#include<conio.h> 

main() 

int a; 

clrscr(); 

printf("a="); 

scanf("%d",&a); 

 

if(a%2==0) 

goto even; 

else 

goto odd; 

 

even: 

printf("even"); 

goto end; 

 

odd: 

printf("odd"); 

goto end; 

 

end: 

printf("program over"); 

getch(); 

 

LOOP 

1.while 

2.do...while 

3.for 

while 

===== 

while(condition) 

statement 

*/ 

 

/*write  program print this message 10 times 

message:  c is a language*/ 

 

#include<stdio.h> 

#include<conio.h> 

main() 

int a=1;/*initialization*/ 

clrscr(); 

while(a <= 10) 

printf("c is a language"); 

a=a+1; 

getch(); 

 

/*note: 

ctrl+break is used to terminate the program*/ 

 

looping statement 

 

1.while 

2.do...while 

3.for 

 

SYNTAX: 

while 

===== 

while(condition) 

statement 

 

 

 

/*write  program print  1 to 10*/ 

 

#include<stdio.h> 

#include<conio.h> 

main() 

int a=1;/*initialization*/ 

clrscr(); 

while(a <= 10) 

printf("%d\n",a); 

a=a+1;  // a++ 

getch(); 

 

#include<stdio.h> 

#include<conio.h> 

main() 

int a=1;/*initialization*/ 

clrscr(); 

while(a <= 100) 

  if(a%5==0) 

  

   printf("%d\n",a); 

  

   a++;  // a++ 

getch(); 

 

 

 

 

 

#include<stdio.h> 

#include<conio.h> 

main() 

int a,b,c=0; 

clrscr(); 

printf("a="); 

scanf("%d",&a); 

while(a>0) 

b=a%10; 

c=c*10+b; 

a=a/10; 

printf("reverse number is=%d",c); 

getch(); 

 

 

 

 

 

Check wheather the given number is palindrome  or   not. 

 

#include<stdio.h> 

#include<conio.h> 

 

 

main() 

int a,b,c=0,k; 

clrscr(); 

printf("a="); 

scanf("%d",&a); 

k=a; 

 

while(a>0) 

b=a%10; 

c=c*10+b; 

a=a/10; 

if(k==c) 

printf("The given number is Palindrome:"); 

else 

printf("The given number is not a  Palindrome:"); 

getch(); 

 

 

 

 

do while 

Syntax: 

 

  

do 

 Statement; 

}while(condition); 

 

 

 

for loop 

syntax:- 

====== 

for(initialization; condition; increment or decrement) 

statement 

*/ 

 

#include<stdio.h> 

#include<conio.h> 

main() 

int i; 

clrscr(); 

for(i=1;i<=5;i++) 

printf("%d\n",i); 

getch(); 

 

/*multiplication table*/ 

#include<stdio.h> 

#include<conio.h> 

main( ) 

int i,j,k; 

clrscr(); 

printf("enter multiplication value="); 

scanf("%d",&j); 

for(i=1;i<=16;i++) 

/*k=i*j; 

printf("%d*%d=%d\n",i,j,k);*/ 

printf("%d*%d=%d\n",i,j,i*j); 

getch(); 

 

Nested for loop 

-- 

 

/*for loop 

syntax:- 

====== 

for(initialization; condition; increment or decrement) 

   for(initialization; condition;      increment or decrement) 

  

   statement 

   

*/ 

 

#include<stdio.h> 

#include<conio.h> 

main() 

int i; 

clrscr(); 

for(i=1;i<=5;i++) 

printf("%d\n",i); 

getch(); 

 

 

/*nested for loop*/ 

#include<stdio.h> 

#include<conio.h> 

main() 

int i,j; 

clrscr(); 

for(i=1;i<=5;i++) 

for(j=1;j<=5;j++) 

printf("%d*%d=%d\n",i,j,i*j); 

printf("\n\n\n"); 

getch(); 

/* 

Step 1 

=== 

i=1 1<=5 

j=1 1<=5 

1*1=1 

j=2 2<=5 

1*2=2 

j=3 3<=5 

1*3=3 

j=4 4<=5 

1*4=4 

 

 

j=5 5<=5 

1*5=5 

j=6 6<=5(false) 

step2 

==== 

i=2 2<=5 

j=1 1<=5 

2*1=2 

j=2 2<=5 

2*2=4 

j=3 3<=5 

2*3=6 

j=4 4<=5 

2*4=8 

j=5 5<=5 

2*5=10 

j=6 6<=5(false) 

 

step-3 

===== 

i=3 3<=5 

*/ 

 

 

 +2 TOP RANKERS