Ex.
No: 1 (a)         Program to implement a Area of a
Circle
Date :
Aim:
Algorithm:
Program :
#include <stdio.h>
#include
<conio.h>     void
main()
{
          double radius,area;
          clrscr();
          Printf(“Enter the Value of Radius:”); Scanf(“%2d\
          n”, &radius);
          area= 3.14 * radius * radius;
          printf("Area of the Circle Value is:%lf", area);
          getch();
Output:
Enter the Value of Radius: 10
Area of the Circle Value is : 314
Result:
Ex. No: 1 (b)          Program to implement a Area of a Triangle
Date :
Aim:
Algorithm:
Program :
#include <stdio.h>
#include
<conio.h>     void
main()
{
          double breath,height,area;
          clrscr();
          Printf(“Enter the Values of Breath and Height:”);
          scanf("%lf%lf", &breath,&height);
          area= 0.5 * breath * height;
          printf("Area of the Triangle Value is:%lf", area);
          getch();
Output:
Enter the Value of Breath and Height: 10 20
Area of the Triangle Value is : 100
Result:
Ex. No: 2 (a)           Program to check whether the given number is Even or
Odd
Date :
Aim:
Algorithm:
Program :
#include <stdio.h>
#include
<conio.h>     void
main()
{
          int number;
          Printf(“Enter the Number:”);
          scanf("%d", &number);
          if ( number % 2 ==1)
                     printf("The Given number is Odd");
          else
                     printf("The Given number is Even");
}
Output:
Enter the Number: 20
The Given number is Even
Enter the Number:15
The Given number is Odd
Result:
Ex. No: 2 (b)        Program to perform a Biggest of 2
Numbers
Date :
Aim:
Algorithm:
Program :
#include <stdio.h>
#include
<conio.h>     void
main()
{
                 int a,b;
                 clrscr();
                 Printf(“Enter the Values of A & B:”);
                 scanf("%d%d",&a,&b);
                 if ( a>b)
                 else        }
                 getch();
printf(“A is Big”);
printf(“B is Big”);
Output:
Enter the Value of A & B: 10 20
B is Big
Enter the Value of A & B: 200 150
A is Big
Result:
Ex. No: 3 (a)            Program to implement Pascal’s
Triangle
Date :
Aim:
Algorithm:
Program :
#include<stdio.h>
#include<conio.h>
void main()
{
int noline,i,j,temp;
clrscr(); printf("\n\
n");
printf("\t\t\t Pascal Triangle\n");
printf("\t\t\t ***************\n\n");
printf("\tEnter The Number Of Line To Print :\t");
scanf("%d",&noline);
for(i=1;i<=noline;i++)
{
for(j=1;j<=noline-i;j++)
printf(" ");
temp=i; for(j=1;j<=i;j+
+) printf("%4d",temp+
+); temp=temp-2;
for(j=1;j<i;j++)
printf("%4d",temp--);
printf("\n\n");
}
printf("\n");
getch();
}
Output:
                          *
                         **
                         ***
                         ****
                        *****
                        ******
Result:
Ex. No: 3 (b)           Program to perform a Factorial of a Number
Date :
Aim:
Algorithm:
Program :
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int i,n,f;
char c;
clrscr();
printf("\n\n\n\t\t\tFactorial Number\n");
do
{
printf("\n\nEnter the number\n");
scanf("%d",&n);
printf("Factorial is %d \n",fact(n)); printf("\
n\nDo you want to continue [Y/N]");
c=getch();
}
while(c=='Y' || c=='y');
}
int fact(int n)
{
int f;
if(n==1)
return(1);
else
f=n*fact(n-1);
return(f);
}
Output:
Enter the Value of Breath and Height: 10 20
Area of the Triangle Value is : 100
Result:
Ex. No: 3 (c)            Program to perform a Fibonacci
Series
Date :
Aim:
Algorithm:
Program :
#include<stdio.h>
#include<conio.h>
void main()
{
int num,fib=0,a=0,b=1; int
i;
clrscr(); printf("\n\
n");
printf("\t\t\tFibonacci Series\n"); printf("\t\t\
t****************\n\n"); printf("\t\tEnter
The Number is :\t"); scanf("%d",&num);
printf("\n\t\tFibonacci Series is :\n");
if(num==0)
printf("0"); else
{
for(i=0;i<num;i++)
{
fib=fib+a;
a=b; b=fib;
printf("\t\t\t\t\t%d\n",fib);
}
}
getch();
}
Output:
Enter the Value of Breath and Height: 10 20
Area of the Triangle Value is : 100
Result:
Ex. No: 4               Program to find the Largest element of an array using the Function
Date :
Aim:
Algorithm:
Program:
             #include <stdio.h>
             int findLarge(int[],int);
             int main()
                 int a[100],a_size,L_Num,i;
                 printf(“Enter size of array: “);
                 scanf(“%d”,&a_size);
                 printf(“Enter the elements into array:\n”); for(i=0;i<a_size;i+
                 +)
                      scanf(“%d”,&a[i]);
                 L_Num=findLarge(a,a_size);
                 printf(“Largest number is: %d\n”,L_Num);
                 return 0;
             int findLarge(int a[],int a_size)
                 int i,Large_num;
                 Large_num=a[0];
                 for(i=1;i<a_size;i++)
                     if(Large_num<a[i])
                       Large_num=a[i];
                 return Large_num;
Output:
      Enter size of array: 5
      Enter the elements into array:
      142        785         272    274      632
      Largest number is: 785
Result:
    Ex. No: 5      Program to Display all Prime numbers between 2 intervals using
    Function
    Date :
    Aim:
    Algorithm:
    Program :
    #include <iostream>
using namespace std;
int check_prime(int); int main() {
   int n1, n2; bool flag;
  cout << "Enter two positive integers: "; cin >> n1 >> n2;
  // swapping n1 and n2 if n1 is greater than n2 if (n1 > n2) {
     n2 = n1 + n2; n1 = n2 -
     n1; n2 = n2 - n1;
  }
  cout << "Prime numbers between " << n1 << " and " << n2 << " are:\n"; for(int i = n1+1; i < n2; +
  +i) {
    // if i is a prime number, flag will be equal to 1 flag = check_prime(i);
    if(flag)
          cout << i << ", ";
    }
    return 0;
}
// user-defined function to check prime number int
check_prime(int n) {
   bool is_prime = true;
    // 0 and 1 are not prime numbers if (n == 0 || n
    == 1) {
       is_prime = false;
    }
    for(int j = 2; j <= n/2; ++j) { if (n%j == 0) {
         is_prime = false; break;
      }
    }
    return is_prime;
}
        Output:
          Enter two positive integers: 12 30
          Prime numbers between 12 and 30 are: 13 17 19 23 29
        Result:
Ex. No: 6             Program to Reverse a String using Recursion
Date :
Aim:
Algorithm:
Program :
#include<stdio.h>
#define MAX 100
char* ReverseOfString(char[]);
              int main()
              {
                 char str1[MAX],*revstr;
                      printf("\n\n Recursion : Get reverse of a string :\n");
                      printf("                                    \n");
                 printf(" Input any string: ");
                 scanf("%s",str1);
                 revstr = ReverseOfString(str1);//call the function ReverseOfString
                 printf(" The reversed string is: %s\n\n",revstr);
                 return 0;
              }
              char* ReverseOfString(char str1[])
              {
                static int i=0;
                static char revstr[MAX];
                if(*str1)
                {
       ReverseOfString(str1+1);//calling the function ReverseOfString itself
       revstr[i++] = *str1;
    }
    return revstr;
}
   Output:
Recursion : Get reverse of a string :
-----------------------------------------
Input any string: w3resource
The reversed string is: ecruoser3w
   Result:
Ex. No: 7              Program to Concatenate 2
Strings
Date :
Aim:
Algorithm:
Program :
          #include<stdio.h>
          #include<conio.h>
          #include<string.h>
          int main()
          {
             char str1[50], str2[50];
             printf("Enter first string: ");
             gets(str1);
             printf("Enter second string: ");
             gets(str2);
             strcat(str1, str2);
             printf("\n String after concatenation is:\n %s", str1);
             getch();
             return 0;
          }
Output:
Enter first string: Mani
Enter second string: Maran
String after concatenation is: Mani Maran
Result:
Ex. No: 8               Program to Store Student Information using Structure and display
it
Date :
Aim:
Algorithm:
Program :
         #include <stdio.h>
         struct student
         {
         char name[50];
         int roll;
         float marks;
         }
         stud[2];
         int main()
         {
         int i;
         printf("Enter information of students:\n");
         // storing information
         for(i=0; i<2; ++i)
         {
         stud[i].roll = i+1;
         printf("\nEnter roll number: %d\n",stud[i].roll);
         printf("Enter name: ");
         scanf("%s",stud[i].name);
         printf("Enter marks: ");
         scanf("%f",&stud[i].marks);
         printf("\n");
        }
        printf("Displaying Information:\n\n");
        // displaying information
        for(i=0; i<2; ++i)
        {
        printf("\nRoll number: %d\n",i+1);
        printf("Name: ");
        puts(stud[i].name);
        printf("Marks: %.1f",stud[i].marks);
        printf("\n");
        }
        return 0;
        }
Output:
Enter the Information of Students:
Enter the roll number:
1 Enter Name: John
Enter Marks: 85
Enter the roll number: 2
Enter Name: Krishna
Enter Marks: 92
Displaying Information:
Roll number: 1
Name: John
Marks: 85
Roll number: 2
Name:
Krishna
Marks: 92
Result:
 Ex. No: 9                    Program to implement the Sequential Access
 File
 Date :
 Aim:
 Algorithm:
 Program:
// Creating a sequential file #include
  <stdio.h>
  int main( void ) {
  unsigned int account; // account number
  char name[ 30 ]; // account name double
  balance; // account balance
  FILE *cfPtr; // cfPtr = clients.dat file pointer
  // fopen opens file. Exit program if unable to create file if (
  ( cfPtr = fopen( "clients.dat", "w" ) ) == NULL )
  { puts( "File could not be opened" );
  } // end if else
  {
      puts( "Enter the account, name, and balance." );
      puts( "Enter EOF to end input." );
      printf( "%s", "? " );
      scanf( "%d%29s%lf", &account, name, &balance );
  // write account, name and balance into file with fprintf
while ( !feof( stdin ) ) {
  fprintf( cfPtr, "%d %s %.2f\n", account, name, balance );
     // while not end of file while ( !feof(
     cfPtr ) ) {
        printf( "%-10d%-13s%7.2f\n", account, name, balance ); fscanf( cfPtr, "%d
        %29s%lf", &account, name, &balance );
        } // end while
        fclose( cfPtr ); // fclose closes the file
        } // end else
Output:
Enter the account, name, and balance.
Enter EOF to end input
        100 Jones 24.98
        200 Doe 345.67
        300 White 0.00
        400 Stone -42.16
        500 Rich 224.62
   Program output:
       Account        Name       Balance
      100             Samuel     24.98
      200             Martin     345.67
      300             White      0.00
      400             Stone      -42.16
      500             Rich       224.62
 Result:
 Ex. No: 10      Program to implement the Random Access
 File
 Date :
 Aim:
 Algorithm:
 Program :
// Creating a random-access file sequentially
#include <stdio.h>
    // clientData structure definition
    struct clientData {
    unsigned int acctNum; // account number char
    lastName[ 15 ]; // account last name char
    firstName[ 10 ]; // account first name double
    balance; // account balance
    }; // end structure clientData int
    main( void ) {
    unsigned int i; // counter used to count from 1-100
    // create clientData with default information struct
    clientData bankClient = { 0, "", "", 0.0 }; FILE
    *cfPtr; // credit.dat file pointer
    // fopen opens the file; exits if file cannot be opened if
    ( ( cfPtr = fopen( "credit.dat", "wb" ) ) == NULL ) {
       puts( "File could not be opened." );
     } // end if else
     {
     // output 100 blank records to file
          for ( i = 1; i <= 100; ++i ) {
          fwrite( &bankClient, sizeof( struct clientData ), 1, cfPtr );
          } // end for
          fclose ( cfPtr ); // fclose closes the file
          } // end else
     } // end main
// Writing data randomly to a random-access file
#include <stdio.h>
     // clientData structure definition struct clientData {
     unsigned int acctNum; // account number char lastName[ 15 ]; // account last name char
     firstName[ 10 ]; // account first name double balance; // account balance
     }; // end structure clientData
     int main( void ) {
     FILE *cfPtr; // credit.dat file pointer
     // create clientData with default information struct clientData client = { 0, "", "", 0.0 };
     // fopen opens the file; exits if file cannot be opened if ( ( cfPtr = fopen( "credit.dat", "rb+" ) ) ==
     NULL ) {
     puts( "File could not be opened." );
         } // end if else {
         // require user to specify account number printf( "%s", "Enter account number"
                " ( 1 to 100, 0 to end input )\n? " ); scanf( "%d", &client.acctNum );
         // user enters information, which is copied into file while ( client.acctNum != 0 ) {
// user enters last name, first name and balance
printf( "%s", "Enter lastname, firstname, balance\n? " );
// set record lastName, firstName and balance value fscanf( stdin, "%14s%9s%lf",
client.lastName,client.firstName, &client.balance );
// seek position in file to user-specified record fseek( cfPtr, ( client.acctNum - 1 ) *
           sizeof( struct clientData ), SEEK_SET );
   // write user-specified information in file
                  fwrite( &client, sizeof( struct clientData ), 1, cfPtr );
// enable user to input another account number printf( "%s", "Enter account number\n? " );
  scanf( "%d", &client.acctNum );
  } // end while
  fclose( cfPtr ); // fclose closes the file
  } // end else
} // end main
OUTPUT:
  Enter account number ( 1 to 100, 0 to end input )
   ? 37
   Enter lastname, firstname, balance
   ? Barker Doug 0.00
   Enter account number
   ? 29
   Enter lastname, firstname, balance
   ? Brown Nancy -24.54
   Enter account number
   ? 96
   Enter account number
   ? 0
Result: