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);
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);
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()
{
Comments
Post a Comment