Showing posts with label C Language. Show all posts
Showing posts with label C Language. Show all posts

Sunday, 26 July 2015

break-statement

When break is encountered inside any loop, control automatically passes to the first statement after the loop.
 A break statement is usually associated with an if.

Example program

//program to print first 6 numbers only
#include<stdio.h>
#include<conio.h>
int main()
{
int i;
for(i=0;i<=10;i++)
{

printf("%d\n",i);
if(i==6)
break;

}
getch();
return 0;

}

output:
0
1
2
3
4
5
6

Though we wrote the program to print 10 numbers, the numbers after 6 are not printed because of the break statement. Here the moment the system encounters the break statement, control automatically passes to the next statement after the loop.

//program to determine whether a number is prime or not
#include<stdio.h>
#include<conio.h>
int main()
{
int num, i;
printf("enter a number\n");
scanf("%d",&num);
i=2;
while(i<=num-1)
{
if(num%i==0)
{
printf("not a prime number");
break;
}
i++;
}
if(i==num)
printf("prime number");
getch();
return 0;
}

output:
enter a number
9
not a prime number

continue statement

If I want to print numbers from 1 to 10 with the exception of 2 how???

continue :When continue is encountered inside any loop, control automatically passes to the beginning of the loop.
A continue is usually associated with an if.

Example
#include<stdio.h>
#include<conio.h>
int main()
{
int i;
for(i=0;i<=10;i++)
{
if(i==2)
continue;
printf("%d\n",i);
}
getch();
return 0;
}

output:
0
1
3
4
5
6
7
8
9
10


//program to print odd numbers

#include<stdio.h>
#include<conio.h>
int main()
{
int i;
for(i=0;i<=10;i++)
{
if(i==2)
continue;
printf("%d\n",i);
}
getch();
return 0;

}

output:
1
3
5
7
9







do-while

Confused with while and do-while?

simple thing- while executes the set of instructions in the loop only if the condition specified is true. On the other hand, do- while executes the set of instructions atleast once what ever the condition may be.

syntax:

while                                                                    do-while

while(i<=10)                                                       do
{                                                                          {
 printf("%d",i);                                                          this;
                                                                                and this;
                                                                           }while(this condition is true);
i++;
}


1.Example program
#include<stdio.h>
#include<conio.h>
int main()
{
while(4<2)
printf("this is while");
return 0;
}


output:
No output will be generated as the condition fails.


#include<stdio.h>
#include<conio.h>
int main()
{
do
   {
      printf("this is do- while");
    }while(5<2);
return 0;
}


output:
this is do-while
since it is do-while the printf statement will be executed atleast once.


Friday, 24 July 2015

Loops-for

for is the most popular looping instruction.The for allows us to specify three things about a loop in a single line:

1.Setting a loop counter to an initial value
2.Testing the loop counter to determine whether its value has reached the number of repetitions desired
3.Increasing the value of loop counter each time the program segment within the loop has been executed.

syntax for for- loop

for(initialization; test counter; increment counter)
{
do this;
do this;
}


//program to print N numbers

#include<stdio.h>
#include<conio.h>
int main()
{
int i,n;
printf("Till which number do you want to print");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
printf("%d\n",i);
}
  getch();
  return 0;
}

output:
Till which number do you want to print 4
0
1
2
3
4


//Calculation of simple interest for 3 sets of p, n, r
























Formats:

 for(i=10;         i;                    i--)
printf("%d",i);

for(i<4;                   j=5;            j=0)
printf("%d",i);


for(i=1;              i<=10 ;             printf("%d",i++))
;


Loops- while

The programs that we have discussed so far used either a sequential or a decision control instruction. In the first one, the calculations were carried out in a fixed order; while in the second one, an appropriate set of instructions were executed depending on the outcome of the condition being tested.

             These programs have a limited scope, because when executed they always perform the same series of actions, in the same way exactly once. But in real life if something is worth doing, it has to be done more than once.

Loops:
           The versatility of the computer lies in its ability to perform a set of instructions repeatedly. This involves repeating some portion of the program either a specified number of times or until a particular condition is being satisfied.This repetitive operation is done through a loop control instruction.


Syntax of while loop:

while(condition)
{


set of statements;
increment statement;


}

//simple programs using while loop

//calculation of simple interest for 3 sets of p, n and r
#include<stdio.h>
#include<conio.h>
int main()
{
int p, n, count;
float r, si;
count=1;
while(count<=3)
{
  printf("enter values of p, n and r\n");
scanf("%d%d%f",&p,&n,&r);
si=p*n*r/100;
printf("simple interest =rs %f\n",si);
count=count+1;
}
return 0;
}

output: 
enter values of p, n and r
1000 5 13.5
simple interest =rs 675.000000
enter values of p, n and r
2000 5 13.5
simple interest =rs 1350.000000
enter values of p, n and r
3500 5 3.5
simple interest =rs 612.500000


//To print numbers

#include<stdio.h>
#include<conio.h>
int main()
{
int i=0,n;
printf("how many numbers do you want to print\n");
scanf("%d",&n);
while(i<=n)
  {    
printf("%d\n",i);
i++;
  }
  getch();
return 0;
}

output:
how many numbers do you want to print
5
0
1
2
3
4
5


//To print even numbers
#include<stdio.h>
#include<conio.h>
int main()
{
int i=1,n;
printf("enter the number\n");
scanf("%d",&n);
printf("0\n");
while(i<=n)
{
if(i%2==0)
printf("%d\n",i);
i++;
}
  getch();
  return 0;
}

output:
enter the number
12
0
2
4
6
8
10
12








Friday, 17 July 2015

Switch

The control statement that allows us to make a decision from the number of choices is called a switch statement.

Syntax:

switch(integer expression)
{
case constant 1:
            do this;
case constant 2:
            do this;
case constant 3:
              do this;
default:
         do this;
}


Examples:
1.//program

#include<stdio.h>
#include<conio.h>
int main()
{
int i=2;
switch(i)
{
case 1:
printf("in class 1");
break;
case 2:
printf("in class 2");
break;
case 3:
printf("in class 3");
break;
default:
printf("in default");

}
getch();
return 0;

}

output:
in class 2


2.//without break

#include<stdio.h>
#include<conio.h>
int main()
{
int i=2;
switch(i)
{
case 1:
printf("in class 1\n");

case 2:
printf("in class 2\n");

case 3:
printf("in class 3\n");

default:
printf("in default\n");

}
getch();

return 0;
}


output:
in class 2
in class 3
in default

//It executes the 2 case and all the remaining cases after the 2 case as the break statement is not present.

//We can write the cases in any order, not necessarily in ascending or descending order.


3.//cases arranged in random order
#include<stdio.h>
#include<conio.h>
int main()
{
int i=2;
switch(i)
{
case 1:
printf("in class 1\n");

case 3:
printf("in class 3\n");

   case 2:
printf("in class 2\n");

default:
printf("in default\n");

}
getch();
return 0;

}

output:
in class 2
in default



4.//Arithmetic operations -break statement is not present


#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,x;
printf("enter two values\n");
scanf("%d%d",&a,&b);
printf("select operation +=1 or -=2 or /=3 or *=4 or %=5\n");
scanf("%d",&x);
switch(x)
{
case 1:
printf("sum of two numbers is %d\n",a+b);
case 2:
printf("difference of two numbers is %d\n",a-b);
case 4:
printf("product of two numbers is %d\n",a*b);
case 3:
printf("division of two numbers is %d\n",a/b);
case 5:
printf("modular division results %d\n",a%b);
default:
printf("enter any one of the operations");
}
getch();
return 0;
}

output:

enter two values
10
2
+=1 or -=2 or /=3 or *=4 or %=5
1
sum of two numbers is 12
difference of two numbers is 8
product of two numbers is 20
division of two numbers is  5
modular division results 0
enter any one of the operations


5.//To print month

#include<stdio.h>
#include<conio.h>
int main()
{
int month;
printf("enter month\n");
scanf("%d",&month);
switch(month)
{
case 1:
printf("january");
break;
case 2:
printf("February");
break;
case 3:
printf("March");
break;
case 4:
printf("April");
break;
case 5:
printf("May");
break;
case 6:
printf("June");
break;
case 7:
printf("July");
break;
case 8:
printf("August");
break;
case 9:
printf("September");
break;
case 10:
printf("October");
break;
case 11:
printf("November");
break;
case 12:
printf("December");
break;
}
getch();
return 0;
}

output:
enter month
5
May






Thursday, 16 July 2015

C language- if-else statement

The if statement will execute a single statement, or a group of statements when the expression following if evaluates to be true.It does nothing when the expression evaluates to false.
     By using if-else statement we can execute one group of statements if the expression evaluates to be true and another group of statements if the expression evaluates to false.


syntax:

if(condition)
do this;
else
do this;


if(condition)
{
execute 1;
execute 2;
}
else
{
execute 3;
execute 4;
}




1.//program to check if the given number is even or odd
#include<stdio.h>
#include<conio.h>
int main()
{
int x;
printf("enter a number\n");
scanf("%d",&x);
if(x%2==0)
printf("the given number is even");
else
printf("the number is odd");
return 0;
getch();

}

output:
enter a number
20
the given number is even


2.//Is 3=3.0?
#include<stdio.h>
#include<conio.h>
int main()
{
int x=3;
float y=3.0;
if(x==y)
{
printf("x and y are equal\n");
printf("3 and 3.0 are equal\n");
}
else
{
printf("x and y are not equal");
}
return 0;
getch();
}

output:
x and y are equal
3 and 3.0 are equal


3.//find error
#include<stdio.h>
#include<conio.h>
int main()
{
int x=2;
if(x==2&&x!=0);
printf("hello\n");
else
printf("bye");
return 0;
getch();
}

output: error
'else' without a previous 'if'


4.//interesting

#include<conio.h>
int main()
{
int x,y,z;
printf("enter three numbers\n");
scanf("%d%d%d",&x,&y,&z);
if(x&&y&&z)  
printf("you entered all non zero numbers\n");
else
printf("you entered a zero");
return 0;
getch();
}

output:
enter three numbers
1
5
8
you entered all non zero numbers
//if(&&5&&8)  is equal to  if(1&&1&&1)







C language- if statement

C has three major decision making instructions-the if statement, the if-else statement, and the switch statement.

In sequential control structure various steps are executed sequentially, we don't have to do anything at all . That is by default, the instructions in a program are executed sequentially. However in reality, we rarely want the instructions to be executed sequentially. Many a times we want a set of instructions to be executed in one situation and a different set of instructions in the other case.


             Hence a decision control instruction can be implemented in C using
1. The if-statement
2.The if-else statement
3.The conditional operators


//Syntax of if-statement

if(condition is true)
execute this statement;


In the () we can write anything which finally results either 1 or 0
If the result is 1 the statement immediately followed by the if-statement is executed then the control shifts to the next statement.

1.//program to allow a user into a website

#include<stdio.h>
#include<conio.h>
int main()
{
int age;
printf("hello user please enter your age\n");
scanf("%d",&age);
if(age>18)
printf("you can see the content of this website");
printf("whether you are >18 or <18 this statement gets printed");
getch();
}


output:
hello user please enter your age
20
you can see the content of this website
whether you are >18 or <18 this statement gets printed


2.//program to print even numbers
#include<stdio.h>
#include<conio.h>
int main()
{
int i, n;
printf("enter the final number");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
if(i%2==0)
printf("%d\n",i);
}
getch();
}

output:
enter the final number
10
0
2
4
6
8
10


3.//calculation of total amount
#include<stdio.h>
#include<conio.h>
int main()
{
int qty,dis=0;
float rate,tot;
printf("enter quantity and rate\n");
scanf("%d%f",&qty,&rate);
if(qty>1000)
dis=10;
tot=(qty*rate)-(qty*rate*dis/100);
printf("total expenses=rs %f\n",tot);
return 0;
getch();
}

output:
enter quantity and rate
1500
10
total expenses =rs 1350.0000


4.//logical condition
#include<stdio.h>
#include<conio.h>
int main()
{
int a=300,b,c;
if(a>=400)
b=300;
c=200;
printf("%d\n%d\n",b,c);
return 0;
getch();
}

output:
0
200


5.//logical statement
#include<stdio.h>
#include<conio.h>
int main()
{
int x=10,y=20;
if(x==y)
printf("%d\n%d\n",x,y);
return 0;
getch();

}

output:
no output as the condition did not satisfy

Monday, 13 July 2015

C language basics 4- search programmes

1.//linear search

#include <stdio.h>
#include<conio.h>

int main()
{
   int array[100], search, c, n;

   printf("Enter the number of elements in array\n");
   scanf("%d",&n);

   printf("Enter %d integer(s)\n", n);

   for (c = 0; c < n; c++)
      scanf("%d", &array[c]);

   printf("Enter the number to search\n");
   scanf("%d", &search);

   for (c = 0; c < n; c++)
   {
      if (array[c] == search)     /* if required element found */
      {
         printf("%d is present at location %d.\n", search, c);
         break;
      }
   }
   if (c == n)
      printf("%d is not present in array.\n", search);
      getch();

   return 0;

}



output:
Enter the number of elements in array
6
14
12
15
16
17
18
Enter the number to search
17
17 is present at location 4




2.//Binary search

#include <stdio.h>
#include<conio.h>

int main()
{
   int c, first, last, middle, n, search, array[100];

   printf("Enter number of elements\n");
   scanf("%d",&n);

   printf("Enter %d integers\n", n);

   for (c = 0; c < n; c++)
      scanf("%d",&array[c]);

   printf("Enter value to find\n");
   scanf("%d", &search);

   first = 0;
   last = n - 1;
   middle = (first+last)/2;

   while (first <= last) {
      if (array[middle] < search)
         first = middle + 1;  
      else if (array[middle] == search) {
         printf("%d found at location %d.\n", search, middle);
         break;
      }
      else
         last = middle - 1;

      middle = (first + last)/2;
   }
   if (first > last)
      printf("Not found! %d is not present in the list.\n", search);
      getch();

   return 0;  

}


output:
Enter number of elements
5
Enter 5 integers
12
18
19
24
56
Enter value to find
24
24 is found at location 3



3.//palindrome ex: 121   1221
#include <stdio.h>
#include<conio.h>

int main()
{
   int n, reverse = 0, temp;

   printf("Enter a number to check if it is a palindrome or not\n");
   scanf("%d",&n);

   temp = n;

   while( temp != 0 )
   {
      reverse = reverse * 10;
      reverse = reverse + temp%10;
      temp = temp/10;
   }

   if ( n == reverse )
      printf("%d is a palindrome number.\n", n);
   else
      printf("%d is not a palindrome number.\n", n);
      getch();

   return 0;

}
output:
Enter a number to check if it is a palindrome or not
121
121 is a palindrome number





4./* Fibonacci Series c language */
#include<stdio.h>
#include<conio.h>

int main()
{
   int n, first = 0, second = 1, next, c;

   printf("Enter the number of terms\n");
   scanf("%d",&n);

   printf("First %d terms of Fibonacci series are :-\n",n);

   for ( c = 0 ; c < n ; c++ )
   {
      if ( c <= 1 )
         next = c;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
      printf("%d\n",next);
   }
   getch();

   return 0;
}


output:
Enter the number of terms
10
0
1
1
2
3
5
8
13
21
34



5.
/* Bubble sort code */

#include <stdio.h>
#include<conio.h>

int main()
{
  int array[100], n, c, d, swap;

  printf("Enter number of elements\n");
  scanf("%d", &n);

  printf("Enter %d integers\n", n);

  for (c = 0; c < n; c++)
    scanf("%d", &array[c]);

  for (c = 0 ; c < ( n - 1 ); c++)
  {
    for (d = 0 ; d < n - c - 1; d++)
    {
      if (array[d] > array[d+1]) /* For decreasing order use < */
      {
        swap       = array[d];
        array[d]   = array[d+1];
        array[d+1] = swap;
      }
    }
  }

  printf("Sorted list in ascending order:\n");

  for ( c = 0 ; c < n ; c++ )
     printf("%d\n", array[c]);
 getch();
  return 0;

}

output:
Enter number of elements
5
Enter 5  integers
2
54
3
15
55
Sorted list in ascending order
2
3
15
54
55










Friday, 10 July 2015

C language basics 3

//Find the errors

1. #include<stdio.h>
#include<conio.h>
int main()
{
int i;
printf("enter the value of i\n");
scanf("%d",&i);
if(i=5)
printf("you entered  5\n");
else
printf("you entered something other than 5\n");
getch();
return 0;
}


output: enter the value of i
  7
you entered  5


2.//largest of three numbers
#include<stdio.h>
#include<conio.h>
int main()
{
int big, a,b,c;
printf("enter the values of a b c\n");
scanf("%d %d %d",&a, &b, &c);
big=(a>b?(a>c?a:c):(b>c?b:c));
printf("largest of three numbers is %d",big);
getch();
return 0;
}

output: enter the values of a b c
1 18 24
largest of three numbers is 24



3.// Interesting program

#include<stdio.h>
#include<conio.h>
int main()
{
int x=3;
float y=3.0;
if(x==y)
   printf("x and y are equal");
   else
      printf("x and y are not equal");
getch();
return 0;
}

output:
x and y are equal



4.//program

#include<stdio.h>
#include<conio.h>
int main()
{
int x=3, y,z;
y=x=10;
z=x<10;
printf("x=%d y=%d z=%d \n",x,y,z);
getch();
return 0;
}


output:

x=10 y=10 z=0



5.//very interesting program

#include<stdio.h>
#include<conio.h>
int main()
{
int i=4, j=-1, k=0,w,x,y,z;
w=i||j||k;
x=i&&j&&k;
y=i||j&&k;
z=i&&j||k;
printf("w=%d\n x=%d\n y=%d\n z=%d\n",w,x,y,z);
getch();
return 0;
}


output:
w=1
x=0
y=1
z=1



6.//not operator

#include<stdio.h>
#include<conio.h>
int main()
{
int i=-3, j=3;
if(!i+!j*1)
printf("expression results 1");
else
printf("expression results 0");
getch();
return 0;
}


output:
expression results 0



//Difference between && and &

7.//program on if condition

#include<stdio.h>
#include<conio.h>
int main()
{
int i=10, j=20;
if((i=5)&&(j=10))
printf("hello");
getch();
return 0;
}


output:
hello



8.//&
#include<stdio.h>
#include<conio.h>
int main()
{
int i=10, j=20;
if((i=1)&(j=1))
printf("hello");
getch();
return 0;
}

output:
hello


Explanation:

In the first program, first expression 1 be executed and then the result of this expression decides the execution of the other statement. If it is false then the AND will be false so it makes no sense to execute the other statement. The expression 2 statement is executed if and only if expression 1 returns true on execution. It is also known as the short circuit operator because it shorts the circuit (statement) on the basis of the first expression’s result. 


Now in the case of & things are different. The compiler will execute both statements and then the result will be analyzed. It’s an inefficient way of doing things because it makes no sense to execute the other statement if one is false because the result of AND is effective only for AND results evaluated to “true” and it’s possible when both statements are true.


//Difference between || and |
9. 
 #include<stdio.h>
#include<conio.h>
int main()
{
int i=10, j=20;
if((i=0)||(j=1))
printf("hello");
getch();
return 0;
}


output:
hello


10.
 #include<stdio.h>
#include<conio.h>
int main()
{
int i=10, j=20;
if((i=0)|(j=1))
printf("hello");
getch();
return 0;
}


output:
hello


Explanation:
 It’s the same as above, in the case of “||” only one statement is executed and if it returns “true” then the other statement will not be executed. But if the first is false then the other will be checked for the value “true”. The reason for this is the way the “or” operator works. The “Or” operator depends on only one true, in other words if any of the expressions are true then the result will be true.








Friday, 26 June 2015

C language basic programs 2

1. //program on fundamental data types
#include<stdio.h>
#include<conio.h>
int main()
{
int a;
float b;
char c;
double d;
a=5;
b=10.2;
c='M';
d=9.325;
printf("%d %f %c %lf",a,b,c,d);
getch();
return 0;
}


output: 5 10.200000 M 9.325000



2.    //to calculate area of rectangle
#include<stdio.h>
#include<conio.h>
int main()
{
int l, b, area, perimeter;
printf("enter values of length and breadth\n");
scanf("%d %d",&l, &b);
area=l*b;
perimeter=2*(l+b);
printf("area of rectangle is %d\n",area);
printf("perimeter of rectangle is %d",perimeter);
getch();
return 0;

}



output: enter values of length and breadth
2 4
area of rectangle is 8
perimeter of rectangle is 12




3.//to calculate area of rectangle
#include<stdio.h>
#include<conio.h>
int main()
{
float r, area, perimeter;
printf("enter the value of radius of circle\n");
scanf("%f",&r);
area=3.14*r*r;
perimeter=(2*3.14*r);
printf("area of circle is %f\n",area);
printf("perimeter of circle is %f\n",perimeter);
getch();
return 0;

}


output: enter the value of radius of circle
              5
area of circle is 78.500000
perimeter of circle is 31.400000




4.//to calculate area of triangle
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int a,b,c,p;
float s,area;
printf("enter the values of a,b,c\n");
scanf("%d%d%d",&a,&b,&c);
p=a+b+c;
s=(a+b+c)/(2.0);
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("area of triangle is %f\n",area);
printf("perimeter of triangle is %d\n",p);
getch();
return 0;

}


output: enter the values of a,b,c
            2 3 4
area of triangle is 2.904737
perimeter of triangle is 9





5.//sawaping of two numbers
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,temp;
printf("enter two numbers\n");
scanf("%d %d",&a,&b);
printf("before swaping the values of a and b are %d %d\n",a,b);
temp=a;
a=b;
b=temp;
printf("after swaping the values of a and b are %d %d\n",a,b);
getch();
return 0;

}

output: enter two numbers
              3 5
before swaping the values of a and b are 3 5
after swaping the values of a and b are 5 3



Thursday, 25 June 2015

C language basics 1

History:

 C language was developed at AT & T's Bell laboratories of USA in 1972. It is designed and written by Dennis Ritchie.

Features of C language:
1.Middle level language
2.Structural
3.Easy to understand
4.Portability i.e., programs written in one system can be copied into another system and can be executed easily
4.More efficient
5.Compile language
6.Windows, Linux and Unix are written in C because of its high performance

Compiler: basically the system understands only machine level language i.e., written in 1's and 0's.
Here compiler does the job of converting the source code to machine level language


Constant:
1. A constant is an entity that doesn't change
2.Alphabets, numbers and special symbols can be used to form constants.

                                                       constants    -  Integer constants -     5, 12, 28, 264, 768 etc

                                                                               Real constants    -      5.20, 6.25, 235.12, 5.21 etc

                                                                              Character constants- 'a', 'h', '9', '=' etc

Variable:
   A variable is an entity that does change.

Ex:        #include<stdio.h>
              #include<conio.h>
              int main()
 {
              int x=10;                  
              printf("the value of x is %d\n",x);
               x=x+1;
              printf("the value of x is %d\n",x);
 getch();
 return 0;
}

output: the value of x is 10
             the value of x is 20

Here x is a variable and 10, 20 are integer constants.

Variable types:
 1. Integer                                  - keyword is int         ex: int a, int x
 2.Real or floating point type    - keyword is float      ex: float area, float average, etc
 3.Character                               - keyword is char      ex: char a, char i, etc

Keywords:
     These are the words whose meaning has already been explained to the c compiler.
By using keywords we can construct the meaningfull statements.

           Ex: break, int, float, char, if, for.....etc
Note: keywords cannot be used as variable names.

Basic programs:

// to print hello

#include<stdio.h>
#include<conio.h>
int main()
{
printf("hello");
getch();
return 0;
}


Description:
#  - Pre processor directive:  it is a program that processes our source code before it is passed to the compiler

In the C Programming Language, the Standard Library Functions are divided into several header files.
The following is a list of functions found within the <stdio.h> header file:

FORMATTED INPUT/OUTPUT FUNCTIONS


fprintf                               Formatted File Write      
fscanf                               Formatted File Read
printf                                Formatted Write
scanf                         Formatted read
sprintf                        Formatted string write
sscanf                       Formatted string read
vfprintf                       Formatted File Write Using Variable Argument List
vprintf                        Formatted Write Using Variable Argument List
vsprintf                      Formatted String Write Using Variable Argument List  


CLOSE FILE
FLUSH FILE BUFFER
OPEN FILE
REOPEN FILE
REMOVE FILE
RENAME FILE
SET BUFFER (OBSOLETE)
SET BUFFER
CREATE TEMPORARY FILE
GENERATE TEMPORARY FILE NAME

CHARACTER INPUT/OUTPUT FUNCTIONS
Read Character from File
Read String from File
Write Character to File
Write String to File
Read Characters from File
Read Character
Read String
Write Character to File
Write Character
Write String
Unread Character



BLOCK INPUT/OUTPUT FUNCTIONS

                         Read Block from File
                         Write Block to File
FILE POSITIONING FUNCTIONS
 Get File Position
fseek                         
File Seek
Set File Position
Determine File Position
Rewind File













conio.h library functions


      All C inbuilt functions which are declared in conio.h header file are given below. 

List of inbuilt C functions in conio.h file:

S.noFunctionDescription
1clrscr()This function is used to clear the output screen.
2getch()It reads character from keyboard
3getche()It reads character from keyboard and echoes to o/p screen
4textcolor()This function is used to change the text color
5textbackground()This function is used to change text background
       

     
main()  
{
     /*main() is a function . A function is nothing but a set of statements.In a C program there can be multiple functions.All statements that belong to main() are enclosed within a pair of braces {} as shown here.*/




}



printf(" enter x value");    :  standard function used to print something on to the screen.
scanf("%d",&x);                :reads values or data from the user through input devices.
getch();                                 :It reads character from keyboard.


void main()   : does not expect any output value at the end of the program

int main()      :expects some integer value at the end of the program


//program to calculate simple interest


#include<stdio.h>

#include<conio.h>
int main()
{
int p,n;
float r,si;
p=1000;
n=3;
r=8.5;
//formula for simple interest 
si=(p*n*r)/100;
printf("%f\n",si);
return 0;
}

output: 255.000000





//To calculate simple interest for any values of p, n and r


#include<stdio.h>

#include<conio.h>
int main()
{
int p,n;
float r,si;
printf("enter values of p, n,r");
scanf("%d %d %f",&p,&n,&r);
si=(p*n*r)/100;
printf("%f",si);
return 0;
}


output: enter values of p, n,r 4 5 2

               0.400000