SOME C PROGRAMS (As discussed in Youtube live on 16/04/2023)

 PROGRAMS


1. Program to read and display the string.

#include<stdio.h>

#include<conio.h>

void main()

{

     char n[20];

     clrscr();

    printf(""Enter your nane :");

    scanf("%s",n);

    printf("\nEntered value of string is %s",n);

    getch();

}

________________________________________________________________________________

2. Program to copy one string to another string

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

     char m[20],n[20];

     clrscr();

    printf(""Enter First String:");

    scanf("%s",m);

   strcpy(n,m);

    printf("\nNow after copy second string is %s",n);

    getch();

}


__________________________________________________________________________________

3. Program to compare two strings (With Case sensitivity)

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

     char m[20],n[20];

     int check;

     clrscr();

    printf(""Enter First String:");

    scanf("%s",m);

   printf(""Enter Second String:");

    scanf("%s",n);

    check=strcmp(m,n);

    if(check==0)

          printf("Given two strings are equal");

    else

          printf("Given two strings are not equal");

    getch();

}

__________________________________________________________________________________

4. Program to compare two strings (Without Case sensitivity)

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

     char m[20],n[20];

     int check;

     clrscr();

    printf(""Enter First String:");

    scanf("%s",m);

   printf(""Enter Second String:");

    scanf("%s",n);

    check=strcmpi(m,n);

    if(check==0)

          printf("Given two strings are equal");

    else

          printf("Given two strings are not equal");

    getch();

}

__________________________________________________________________________________

5. Program to describe concept of recursion (Factorial of a number)

#include<stdio.h>

#include<conio.h>

#include<string.h>

int fact(int x);

void main()

{

     int n;

     clrscr();

     printf("Enter any number :");

     scanf("%d",&n);

     printf("\n Factocial of %d is %d",n,fact(n));

     getch();

}

void fact(int x)

{

      if(x==0)

             return(1);

     else

            return(x*fact(x-1));

}

___________________________________________________________________________________

6. Program to describe concept of recursion (Reverse of string)

#include<stdio.h>

#include<conio.h>

#include<string.h>

int reverse(char x[]);

void main()

{

      int n[20];
      clrscr();
      printf("Enter any string :");
      scanf("%s",n);
      reverse(n);
      getch();
}

void reverse(int x[])
 {
       if(strlen(x)==0)
            return;
       else
           reverse(x+1);
}
_________________________________________________________________________________

You can try these programs on your computer with turbo c or turbo c++ compiler.     

Comments

Popular posts from this blog

INTRODUCTION TO LANGUAGES

DECISION MAKING STATEMENTS IN C