Pages

Thursday, 27 May 2021

Programs in turboc3: Functions - Types of Functions

Syntax:
return type      function name (argument list)
                       {
                         Body of the loop
                       }
Characteristics  of a function :
1.Function declaration or proto type
2.Calling function sum();
3.Called function can be divided into 4 categories:
      (i) Function with no return and no argument
     (ii) Function with no return and with argument
     (iii) Function with return and with no argument
     (iv) Function with return and with argument

Note:
1. The parameters which are used under calling functions are called Actual parameters.
2. The parameters which are used under called functions are called Dummy parameters.

/*Function with no return and no argument*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void sum(void);   /*Function Declaration or Proto Type*/
void main()
{
clrscr();
sum();                     /*Calling Function*/
getch();
}

Void sum(void)         /*called function*/
{
   int a,b,c;
   printf(“enter a,b values:”);
   scanf(“%d%d”,&a,&b);
   c=a+b;
   printf(“sum is %d”,c);
}
 
output:

/*Example2:Function with no return and no argument*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void mul(void);
 /*Function Declaration or Proto Type*/
void main()
{
clrscr();
mul();       /*calling function*/
getch();
}

void mul(void)     /*called function*/
{
   int a,b,c;
   printf(“enter a,b values:”);
   scanf(“%d%d”,&a,&b);
   c=a*b;
   printf(“multiplication is %d”,c);
}

output:
/* Function with no return and with argument*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void sum(int,int);        
 /*Function Declaration or Proto Type*/
void main()
{
   int a,b;
   clrscr();
   printf(“enter a,b values:”);
   scanf(“%d%d”,&a,&b);
   sum(a,b);    /*calling function*/            // actual parameters
   getch();
}

void sum(int p,intq)      *called function*/       // dummy parameters
{
   int r;
   r=p+q;
   printf(“sum is %d”,r);
}

output:

/* Example 2:Function with no return and with argument*/ 
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void mul(int,int);
  /*Function Declaration or Proto Type*/
void main()
{
   int a,b;
   clrscr();
   printf(“enter a,b values:”);
   scanf(“%d%d “,&a,&b);
   mul(a,b);       /*calling function*/   
   getch();
}

void mul(int p,intq)    /*called function*/
{
   int r; 
   r=p*q;
   printf(“multiplication is %d”,r);
}

output:

/* Function with return and with no argument*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
int sum(void);
  /*Function Declaration or Proto Type*/
void main()
{
   int c;
   clrscr();
   c=sum();    /*calling function*/
   printf(“sum is %d”,c);
   getch();
}
 int sum(void)   /* called function*/
 {
    int p,q,r;
    printf(“enter p,q values:”);
    scanf(“%d%d”,&p,&q);
    r=p+q;
    return r;
 }

output:
/* Example2:Function with return and with no argument*/ 
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
int mul(void);
  /*Function Declaration or Proto Type*/
void main()
 {
    int c;
    clrscr();
    c=mul();    /*calling function*/
    printf(“multiplication is %d”,c);
    getch();
 }
   
int mul(void)   /*called function*/
   {
      int p,q,r;
      printf(“enter p,q values”);
      scanf(“%d%d”,&p,&q);
      r=p*q;
      return r;
    }
 output:

/*Function with return and with argument*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
int sum(int,int);      
  /*Function Declaration or Proto Type*/
void main()
{
   int a,b,c;
   clrscr();
   printf(“enter a,b values”);
   scanf(“%d%d”,&a,&b);
   c=sum(a,b);        /*calling function*/      // actual parameters
   printf(“sum is %d “,c);
   getch();
}
int sum (int p,int q)    /*called function*/         // dummy parameters
{
   int z;
   z=p+q;
   return z;


output:
/*Example 2:Function with return and with argument*/ 
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
int mul(int,int);
  /*Function Declaration or Proto Type*/
void main()
{
   int a,b,c;
   clrscr();
   printf(“enter a,b values”);
   scanf(“%d%d”,&a,&b);
   c=mul(a,b);
   printf(“multiplication is %d “,c);
   getch();
}
int mul(int p,int q)
{
    int z;
    z=p+q;
    return z;
}
 
output:

Tuesday, 25 May 2021

Programs in turboc3: Recursions - factorial,multiplication,power,GCD,Fibonacci,Towers of hanoi

/*Factorial of a number 'n' i.e below 8 using recursion  */

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
int fact(int n);  /* function declaration */
void main()
{
  int n,f;
  clrscr();
  printf(“enter any value:”);
  scanf(“%d”,&n);
  f=fact(n);          /* calling function */
  printf(“\n factorial of %d is %d”,n,f);
  getch();
}

int fact (int n)    /* called function */
{
  int f;
  if(n==1)
  return 1;
  f=n*fact(n-1);
  return (f);
}

Output:


/*Factorial of a number 'n' i.e above 8 using recursion  */
#include<stdio.h>
#include<conio.h>
long factr(int); /* function declaration */
void main()
{
 long fact;
 int n;
 clrscr();
 printf("enter any value:\n");
 scanf("%d",&n);
 fact=factr(n);    /* calling function */
 printf("factorial of %d = %ld",n,fact);
 getch();
 }

 long factr(n)   /* called function */
  {
  long fac;
  if(n==1)
  return 1;
  fac=n*factr(n-1);
  return (fac);
  }


/*Multiplication of two numbers using recursion*/

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include <math.h>
int mult (int,int)    /* function declaration */
void main()
{
  int a,b,c;
  clrscr();
  printf(“enter any two numbers:”);
  scanf(“%d%d”,&a,&b);
  c=mult(a,b);     /* calling function */
  printf(“multiplication of %d and %d is %d”,a,b,c);
  getch();
}

int mult (int a,int b)    /* called function */
{
   if(b==1)
   return a;
   c=b+mult(a,b-1);
   return (c);
}

Output: 

/*Power of two numbers using recursion*/

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
int a,b,c;
int pow(int,int);
void main()
{
  int c;
clrscr();
printf(“enter any two numbers:”);
scanf(“%d%d,&a,&b);
c=pow(a,b);
printf(“\n power of %d and %d is %d”,a,b,c);
getch();
}

int pow (int a,int b)
{
   int c;
   if(b==0)
   return 1;
   c=a*pow(a,b-1);
   return (c);
}

Output:

/*GCD of two numbers using recursion*/

#include<stdio.h>
#include<conio.h>
int gcd(int,int); /* function declaration */
void main()
{
 int a,b,c;
 clrscr();
 printf("\n enter any two values:\n");
 scanf("%d%d",&a,&b);
 c=gcd(a,b);   /* calling function */
 printf("GCD of %d and %d = %d",a,b,c);
 getch();
}

 int gcd(int m,int n)    /* called function  */
 { int x;
  if(n==0)
  return m;
  if(n>m)
   return (gcd(n,m));
  else
   x=m%n;
  return(gcd(n,x));
 }

Output:

/* Fabinacci series using recursion*/

#include<stdio.h>
#include<conio.h>
int n,fib;   /* global variable */
int fibon(int); /* function declaration */
void main()
{
 int i;
 clrscr();
 printf("enter any value:\n");
 scanf("%d",&n);
 printf("\n Fabinacci series of %d: \n",n);
 for(i=0;i<n;i++)
 {
 fib=fibon(i);     /* calling function */
 printf("%d\t",fib);
 }
 getch();
}

 int fibon(n)  /* called function */
 {
  int a,b;
  if(n<=1)
  return n;
  a=fibon(n-1);
  b=fibon(n-2);
  return (a+b);
 }

Output:


/* Towers of Hanoi using recursion */
#include<stdio.h>
#include<conio.h>
void hanoi(int,char,char,char); /* function declaration */
void main()
{
 int n;
 clrscr();
 printf("\n Enter no. of disks to be moved:\n");
 scanf("%d",&n);
 hanoi(n,'X','Z','Y');
 getch();
}

 void hanoi(int n,char initial,char final,char temp)
 {
  if(n==1)
  {
  printf("move disk 1 from needle  %c to %c\n",initial,final);
  return;
  }
 hanoi(n-1,initial,temp,final);
 printf("move disk %d from needle  %c to %c\n",n,initial,final);
 hanoi(n-1,temp,final,initial);
 }

output:

Friday, 14 May 2021

Programs in turboc3 : Strong ,Armstrong,Perfect ,Magic, Palindrome Number including min and max ranges &Reverse,Fibonacci series

/ * Strong Number * /

Definition :A number is called strong number if sum of it's factorials of it's digits is equal to number itself. 

Example : 145

           = 1! + 4! + 5! 

           = 1+24+120 

           =145

Program :
 #include<stdio.h>
 #include<conio.h>
  void main( ) 
  {
      int n, i, f, r, sum=0, tmp;
      clrscr( ) ;
      printf(" Enter any number ") ;
      scanf("%d", &n) ;
       tmp=n;
       while(n) or while (n! =0) 
        {
            i=1 ;
            f=1 ;
            r=n%10 ;
             while (i<=r) 
              {
                  f=f * i ;
                   i ++ ;
              }
                sum=sum+f ;
                   n=n/10 ;
         }
            if(sum==tmp) 
              printf("\n%d is Strong number ", tmp) ;
            else
               printf(“\n%d is not a strong number", tmp) ;
     getch ( );
   }


/ * Strong number range in between min &max */ 

#include<stdio.h>
#include<conio.h>
 void main( )
 {
    long int min, max, n, i, f, r, sum,tmp;
    clrscr( ) ;
    printf(" \nEnter minimum number ") ;
    scanf("%ld",&min) ;
    printf("\n Enter maximum number ") ;
    scanf("%ld",&max) ;
    printf("\nStrong numbers are:") ;
      for(n=min;n<=max;n++)
{
tmp=n;
sum=0;
while (tmp)
   {
     i=1 ;
     f=1 ;
     r=tmp%10 ;
     while (i<=r)
       {
  f=f * i ;
   i ++ ;
       }
    sum=sum+f ;
    tmp=tmp/10 ;
  }
if(sum==n)
  printf("\n%ld is Strong number", n);
       }
       getch ( );
   }

Output:

             1        2      145      40585


/*   Armstrong Number */

Definition:- Those number whose sum of its digits to power of number of its digits is equal to that number is known as Armstrong number.

      For example : 153,  370, 371

      Total  Digits in 153 is  3

      And 13 +53+33 =1+125+27=153

      For example : 1634

      Total Digits in 1634 is 4

       And 14+64+34+44=1+1296+81+256 =1634

Program :- 
    #include<stdio.h>
    #include<conio.h>
    void main( )
    {
       int  n,r, sum=0,tmp ;
       clrscr( ) ;
       printf(“Enter any number:”) ;
       scanf(“%d”,&n) ;
       tmp=n ;
       while(n)
        {
          r=n%10 ;
          n=n/10 ;
         sum=sum+(r*r*r*) ;
        }
      if(sum==tmp) 
        printf(“\n%d  is an Armstrong number”,tmp) ;
      else
         printf(“\n%d is not an Armstrong number”,tmp) ;
     getch( ) ;
   }


/* Min & Max range of an Armstrong number */
     #include<stdio.h>
     #include<conio.h>
     void main( )
     {
       int min,max,n,sum=0,r,tmp ;
       clrscr( ) ;
       printf(“\nEnter min number:”) ;
       scanf(“%d”,&min) ;
       printf(“\nEnter max number:”) ;
       scanf(“%d”,&max) ;
       printf(“\n Armstrong number is the given range :”) ;
       for( n=min ; n<=max ; n++)
        {
          tmp=n ; 
          sum=0 ;
          while(tmp!=0)
           { 
             r=tmp%10 ;
             tmp=tmp/10 ;
             sum=sum+(r*r*r) ;
           }
          if(sum==n)
            printf(“\n%d is  Armstrong number”,n) ;
       }
     getch( ) ;
  }


/*Perfect Number*/

Definition:-Perfect number is a positive number whose sum of all positive divisors excluding that number is equal to that number is known as Perfect number.

For example: 6 is a perfect number , since divisor of 6 are 1,2 and 3. Sum of it's divisor is 1+2+3= 6

28=> 1,2,4,7,14        1+2+4+7+14 = 28

496,

8128.

Program :-
#include<stdio.h>
#include<conio.h>
void main( )
{
   int  n,i=1,sum=0,tmp ;
   clrscr( ) ;
   printf(“Enter any number:”) ;
   scanf(“%d”,&n) ;
   tmp=n ;
   while(i<n)
     {
       if (n%i ==0) 
        sum=sum+i ;
      i++;
     }
   if(sum==tmp)
     printf(“\n%d  is an Perfect number”,tmp);
   else
      printf(“\n%d is not an Perfect number”,tmp);
  getch();
}


/*Min & Max  range of an Perfect number*/
#include<stdio.h>
#include<conio.h>
void main()
{
   int min,max,n,sum=0,i,tmp ;
   clrscr() ;
   printf(“\nEnter min number:”) ;
   scanf(“%d”,&min) ;
   printf(“\nEnter max number:”) ;
   scanf(“%d”,&max) ;
   printf(“\nPerfect number is the given range:”) ;
   for(n=min;n<=max;n++)
     {
       i=1 ;
      sum=0 ;
      while(i<n)
        {
          if(n%i==0) 
            sum =sum+i ;
          i++ ;
        }
      if (sum ==n) 
        printf("\n%d is Perfect number”, n) ;
    }
  getch ( ) ;
}


/*Prime number*/

Definition:- A natural number greater than one has not any other divisors except 1 and itself.In other word we can say which has only two divisors 1 and number itself.

For example:- 5 divisiors are 1 and 5.

#include<stdio.h>
#include<conio.h>
void main( )
{
  int n,i=1,count=0 ;
  clrscr( ) ;
  printf("Enter any number") ;
  scanf("%d",&n) ;
  while(i <= n)
   {
      if( (n%i==0) && (n%n==0) )
      count++ ;
      i++ ;
   }
  if(count==2)
       printf("\n%d is a Prime number",n) ;
 else
       printf("%d is not a prime number",n) ;
 getch( ) ;
}


/*Prime number range in between min and max*/
#include<stdio.h>
#include<conio.h>
void main()
{
  int min,max,n,i,count;
  clrscr( );
  printf("\nEnter min number");
  scanf("%d",&min);
  printf("\nEnter max number");
  scanf("%d",&max);
  printf("\nPrime number in the given range:");
  for(n=min ; n<=max ; n++)
    {  
       i=1;
       count=0;
       while(i<=n)
          {
            if( (n%i==0) && (n%n==0) )
             count++;
            i++;
          }
       if(count == 2)
          pf("\n%d is Prime number”,n);
    }
 getch( );
}

/*Magic number*/

Definition:-A number is said to be a magic number if the reverse of the square of the number is equal to the given number reverse and its square.


For eg: (12) square =144 reverse of 144 is 441
            (21) square= 441

             (13) square=169 reverse of 169 is 961
             (31) square=691


Program:-
#include<stdio.h>
#include<conio.h>
void main ()
{
  int , i ,j,k,n ;
  clrscr( ) ;
  printf(“Enter  any  number”) ;
  scanf(“%d”, &n) ;
  while (i>n)
   {
     i=n*n ;
     j=0 ;
    while(i>0)
      {
         j=j * 10 + i % 10 ;
         i = i / 10 ;
      }
     i=n ;
     k=0 ;
     while(i>0)
       {
         k=k*10+i%10 ;
         i=i/10 ;
       }
     if(k*k==j)
       printf (“\nMagic  number”) ;
     else
        printf (“\nNot a Magic  number” ) ;
   }
 getch();
}


/*Magic number range in between min and max*/
#include<stdio.h>
#include<conio.h>
void main ( )
{
   int i,j,k,n,min,max  ;
   clrsccr() ;
   printf (“\nEnter min number “) ;
   scanf(“%d”,&min );
   printf (“\nEnter max number” ) ;
   scanf(“%d”,&max) ;
   for (n=min;  n<=max  ; n++)
    {
      i=n*n ;
     j=0 ;
    while(i>0)
      {
         j=j * 10 + i % 10 ;
         i = i / 10 ;
      }
     i=n ;
     k=0 ;
     while(i>0)
       {
         k=k*10+i%10 ;
         i=i/10 ;
       }
     if (k * k == j)
         printf (“\n%d  is a Magic number” , n );
    } 
  getch() ;
}


/*Palindrome number */

Definition: A number is caller palindrome number if it remain some when it's digits are reversed

For Example   : 121 is palindrome number, when we will increase ln digit it will remain same number i. e  121

Program :- 
#include <stdio.h>
#include <conio.h>
void main( ) 
{
  int n, r, tmp, sum=0 ;
  clrscr( ) ;
  printf(" Enter any number ") ;
  scanf("%d ", &n) ;
  tmp=n ;
  while (tmp) 
   {
     r=n%10 ;
     r=n/10 ;  
    sum= sum * 10 +r ;
   }
  if (sum ==tmp) 
       printf("\n%d is a Palindrome number ", tmp) ;
  else
       printf("\n%d is not a Palindrome number ",) ;
  getch( ) ;
 }


/* Palindrome number range in between min and max */
#include<stdio.h>
#include<conio.h>
void main ( )

  int  min, max, n, r,sum=0, tmp ;
  clrscr( ) ;
  printf ("\nEnter min number: ") ;
  scanf(“%d”,&min) ;
  printf(“\nEnter max number:”) ;
  scanf ("%d", &max) ;
  printf (" \nPalindrome number in the given range ") ; 
  for ( n=min, n<=max; n++)
   { 
      tmp=n ;
      sum=0 ;
      while (tmp) 
        {
           r=tmp%10 ;
           tmp=tmp/10 ;
           sum=sum * 10 + r ;
         }
       if (sum==n) 
          printf ("\n%d is Palindrome number ", n) ;
    }
  getch( ) ;
 }


/* Reverse the given number & sum */
#include<stdio.h>
#include<conio.h>
void main( )
{
  int n,r,tmp,rev=0,sum=0;
  clrscr( );
  printf("Enter any number");
  scanf("%d",&n);
  tmp=n;
  while(n)
     {
        r=n%10;
        n=n/10;
        rev=rev*10+r;
        sum=sum+r;
      }
  printf("\n%d Reverse number is %d:",tmp,rev);
  printf("\n sum of the reverse number is %d:",sum);
  getch( );
}


/*Factorial of a given number*/
 #include<stdio.h>
 #include<conio.h>
 void main( )
 {
   int n,f=1,tmp;
   clrscr( );
   printf("Take any number");
   scanf("%d",&n);
    tmp=n;
    while(n)
      {
        f=f*n;
        n--;
      }
      printf("\n%d factorial is %d",tmp,f);
   getch( );
  }

output :- Enter any number : 4

              4 factorial is      24 


/*Write a ‘C’ program to illustrate Fibonacci series*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
  int n;i,past=0,present=1,future;
  clrscr();
  printf(“enter any number: “);
  scanf(“%d”,&n);
  printf(“%d%d”,past,present);
  future=past+present;
  printf(“%d”,future);
  for(i=0;i<n-3;i++)
    {
       past=present;
       present=future;
       future = past + present;
       printf("\t %d", future );
    }
  getch();
}


Input: n=5


Output:        0          1         1

                 Past      present      future

                  0                 1           1               2

                           Past       present      future

                   0               1              1         2           3

                                                       Past      present     future


Saturday, 1 May 2021

CONTROL STRUCTURES --Case control structures

1)”Break” Statement:

When a break statement appears in a loop or in switch control structure. A break statement inside the body of a loop breaks completely out of the loop no more instructions in the body of the loop are executed. It can be used within for, while, switch statements. The break statement can be written as ‘ break; ’ without any expression (or) statements.

2)”Continue” Statement:

The continue statement just skips any statement after it on that iteration of the loop. The current iteration of the loop is terminated and the loop statement is executed again, as if the last instruction of the loop body has been reached. The continue statement is written as ‘continue;‘ without any expression (or) statement.



Write a ‘C’ program to illustrate “continue” statement.
#include<stdio.h>
#include<conio.h>
void main()
{
  int n,i;
  clrscr();
  printf(“enter any number: “);
  scanf(“%d”,&n);
  for(i=1;i<=10;i++)
   {
    if(n==i)
      continue;
    else
      printf(“%d”,i);
  }
getch();
}
Output- enter any number: 5
1 2 3 4 6 7 8 9 10

3)”Goto” statement:
These statements are classified into two types. They are,
 1. Forward jump.
 2. Backward jump.

Write a ‘C’ program to illustrate Forward jump.
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“Start of the program”);
goto label;
label:
printf(“\n Entered into the inside label”);
printf(“\n End of the program”);
getch();
}
Output: 
Start of the program
Entered into the inside label
End of the program

Write a ‘C’ program to illustrate Backward jump:
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“\nStart of the program”);
label:
printf(“\n I am inside of the label”);
goto label;
printf(“\n End of the program”);
getch();
}

Output: 
I am inside of the label will be printed infinite times 

CONTROL STRUCTURES --Loop control structures

These are also called as iterative or repetitive control structures

Loop :Some set of statements execute multiple time loops are of 2 types;

  1.  Entry controlled Loop Structures
  2.  Exit controlled Loop Structures

1. Entry controlled Loop Structure :-

These Loops are also called top tested loops. In this the condition  is checked before entering into the body of the loop & the body of the loop is executed until the condition is false



2. Exit controlled Loop Structure :-

These loops are also called bottom tested loop. In this first body of the  loop is executed, then the condition is evaluated, the body of the loop is executed until the condition is false 

 

Note:

  • While for are called entry Control Loop Structure
  • Do while is called exit Control Loop Structure

1) "While" Statement:-

Syntax:

while ( condition)

{

body of the loop

}

/* Write a program to print first 10 numbers using for statement */ 

#include<stdio.h>
#include<conio.h>
void main ( )
{
int n=1 ;
clrscr ( ) ;
while (n<= 10)
{
printf ("%d", n) ;
n= n+1;
}
getch();
}

2) "Do  while " Statement :-

Syntax : 

do

{

body of the loop

}

while ( condition) ;

/* Write a program to print  first  10 numbers using do while statement. */

#include<stdio.h>
#include<conio.h>
void main( )
{
int n=1;
clrscr ( ) ;
do
{
printf("%d", n) ;
n =n+1;
while (n<=10) ;
getch( ) ;
}

3) "for" Statement:-

for (initialization; condition; Inc / dec)

{

body of the loop

}

// Write a program to print first 10 numbers using for statement.

#include<stdio.h>
#include<conio.h>
void main( )
{
int n;
clrscr ( ) ;
for (n=1; n<=10; n++)
{
printf("%d", n) ;
}
getch( ) ;
}

/* Write a program to print first 10 numbers in reverse order using while statement.*/

#include<stdio.h>
#include<conio.h>
void main ( ) 
{
int n=10;
clrscr( ) ;
while (n>=1)
{
printf ("%d", n) ;
n=n-1;
}
getch( ) ;
}

/*Write a program to print first 10 numbers in reverse order using do while statement.*/

#include<stdio.h>
#include<conio.h>
void main ( )
{
int n=10;
clrscr ( ) ;
do
{
printf ("%d", n) ;
n =n-1;
}while (n>=1) ;
getch( ) ;
}

/* Write a program to print first 10 numbers in reverse  order
using for statement.*/
# include<stdio.h>
#include<conio.h>
void main ( )
int n;
clrscr( ) ;
for (n= 10; n>=1; n- - )
{
printf("%d", n) ;
}
getch( ) ;
}

// Write a 'C' program to skip a no. of given  n numbers.
#include<stdio.h>
#include<conio.h>
void main ( )
{
intn,i=1;
clrecr ( ) ;
printf(" enter any number ") ;
scanf("%d", &n) ;
while (i<=10)
{
if ( n == I)
printf ("\n") ;
else
printf ("%d", I) ;
i++
}
getch( ) ;
}

Do  while
# include<stdio.h>
#include<conio.h>
void main( )
{
int n, i=1;
clrscr( ) ;
do
{
printf (" enter any number ") ;
scanf("%d", &n) ;
}
do
{
if (n ==i)
printf ("\n")
else
printf ("%d", i);
i++ ;
}
while (i<=10) ;
getch( ) ;
}

For
#include<stdio.h>
#include<conio.h>
void main (  )
{
int n, i=1;
clrscr( ) ;
pf("enter any number") ;
sf("%d", &n) ;
for(i=1, i<10, i++) 
 {
if(n==i) 
pf("\n") 
 }
else
 {
pf("%d", n);
 }
getch ();
}

Write a program to print 4 th table
#include<stdio.h>
#include<conio.h>
void man () 
{
int n,i=1, x;
pf("enter any number ") ;
sf("%d", & n) ;
while (I<=10) 
 {
 x=n*i;
pf("\n%d*%d=%d", n, i, x) ;
i++;
 }
getch () ;
}

Do while
#include <stdio.h>
#include<conio.h>
Void main()
{
int n, i=1, x;
Clrscr() ;
pf(" enter any number") 
sf("%d", &n) ;
do
  {
  x=n*i;
pf("\n%d*%d=%d", n, i, x) ;
i++; 
}while (i<=10) ;
getch () ;
}

for:
#include <stdio.h>
#include<conio.h>
void main () 
{
int n, i=1.x;
Clrscr() ;
pf("enter any number ") ;
sf("%d", &n) ;
for(i=1, i<=10;i+++) 
  {
  x=n*i; 
pf("\n%d*%d=%d", n, i,x);
  }
getch () ;
}

Write a 'c' program to check whether the given no is a palindrome Or not
#include<stdio.h>
#include<conio.h>
void main () 
{
int n, tmp, r, sum=0
Clrscr
pf(" enter any number ") ;
sf("%d", &n) ;
tmp=n;
while (n) 
{
  r=n%10;
  n=n/10;
  Sum=sum*10+r;
  }
if(sum=tmp) 
  {
pf("%d is a palindrome", tmp) ;
  }
else
  {
pf("%d is not a palindrome", tmp) ;
  }
getch () ;
}

Write a 'c' program to find the factorial of a given number
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main () 
{
int n, f=1;
clrscr() ;
pf("enter any number ") ;
sf("%d", &n) ;
while (n) 
  {
  f=f*n;
n--;
  }
pf("%d factorial is%d", n, f) ;
getch () ;
}

Do while
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main () 
{
int n, f=1;
clrscr() ;
pf(" enter any number ") ;
sf("%d" &n) ;
do
  {
  n=f*n;
  n--;
  }while(n);
pf("%d factorial is%d", n, f) ;
getch () ;
}

For
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main () 
int n, f=1;
clrscr () ;
pf("enter any number ") ;
sf("%d, &n) ;
for(" n! =0, n--") 
  {
  f=f*n;
  } 
pf("%d factorial is%d", n, f) ;
getch () ;
}

Write a c program to check whether the given number is prime or not
#include <stdio.h>
#include <math.h>
#include <conio.h>
void main () 
{
int i=1, n, a=0;
Clrscr();
pf("enter any number ") ;
sf("%d", &n);
while (i<=n) 
 {
if( (n%i) ==0&&(n%n==0) ) 
a++;
i++;
  }
if (a==2) 
  {
pf(%d is a prime number", n) ;
  }
else
  { 
pf(" %d is not a prime number ", n) ;
  }
getch () ;
}

Do while
#include <stdio.h>
#include <math.h>
#include <conio.h>
void main()
{
int i=1, n,a=0;
clrscr() ;
pf(" enter any number ") ;
sf("%d", &n) ;
do
  {
if( (n%i==0) &&(n%n==o) ) 
a++;
i++;
}while (i<=n); 
if (a=2) 
  {
pf(%d is a prime number", n) ;
  }
else
  {
pf(%d is not a prime number ;n) ;
  }
getch () ;
}

For
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main
{
int n, i=1, a=0;
Clrscr;
pf("enter any number ") ;
sf("%d", &n) ;
for(i=1, i<=n, i++) 
  {
if ( (n%i==0) &&(n%n==0)) 
    {
    a++
    }
  }
if(a==2) 
  {
pf(" %d is a prime number ", n) ;
  }
else
  {
pf("%d is not a prime number", n) ;
  }
getch () ;
}

Write a c program to check whether the given number is an arm strong number Or not
#include <stdio.h>
#include <conio.h>
#include <math.h>
voidmain () 
{
int n, tmp, r, sum=0;
clrscr() ;
pf(" enter any number ") ;
sf("%d" , &n) ;
tmp=n
while (n) or (n!=0) 
  {
  r=n%10
  n=n/10
sum=sum+(r*r*r);
  }
if(sum=tmp) 
  {
pf("%d is an arm strong number", tmp) ;
  }
else
  {
getch () ;
}

Write a ‘C’ program to check whether the entered number is a perfect or not.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i=1,n,sum=0,tmp;
clrscr();
printf("enter any number:");
scanf("%d",&n);
tmp=n;
while(i<n)
{
if(n%i == 0)
{
sum =sum+i;
}
i++;
}
if(tmp == sum)
{
printf("%d is a perfect number",tmp);
}
else
{
printf("%d is not a perfect number",tmp);
}
getch();
}

Write a ‘C’ program to find the sum of two given numbers without using ‘+’ sign.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,r;
clrscr();
printf(“enter two numbers: “);
scanf(“%d%d”,&a&b);
r=a - ~ b – 1;
printf(“sum is %d”,r);
getch();
}

Write a ‘C’ program to find the difference between two numbers without using ‘ – ‘ sign.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,r;
clrscr();
printf(“enter any two numbers: “);
scanf(“%d”,&n);
r = a + ~ b + 1;
printf(“Difference is %d”,r);
getch();
}

Write a ‘C’ program to check whether the entered number is strong number or not.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,f,r,I,tmp,sum = 0;
clrscr();
printf(“enter any number: “);
scanf(“%d”,&n);
tmp = n;
while(n) or (n!=0)
 {  
  f=1,i=1;
  r=n%10;
while(i<=r)
   {
    f=f*I;
i++;
   }
sum=sum+f;
   n=n/10;
  }
if(sum==tmp)
printf(“%d is a strong number“,tmp);
else
printf(“%d is not a strong number”,tmp);
getch();
}

Write a ‘C’ program to illustrate Fibonacci series.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
intn;i,past=0,present=1,future;
clrscr();
printf(“enter any number: “);
scanf(“%d”,&n);
printf(“%d%d”,past,present);
future=past+present;
printf(“%d”,future);
for(i=0;i<n-3;i++)
 {
past=present;
present=future;
future=past+present;
printf(“%d”,future);
 }
getch();
}

Input: n=5
Output: 0 1 1
          Past           present          future
             0 1            1 2
                   Past           present          future
0 1    1               2             3
                                              Past           present          future

Programs in turboc3 : Files

File Handling in C File Handling concept in C language is used for store a data permanently in computer. Using this concept we can store our...