Professional Documents
Culture Documents
Program No. 1
Program No. 1
Program No. 1
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
char str[10];
int i;
cout<<"Enter the string = ";
gets(str);
cout<<"length of string is = ";
i=strlen(str);
cout<<i;
getch();
}
OUTPUT:
PROGRAM NO. 2
#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
void main()
{
char a[20];
int wc=1;
clrscr();
cout<<"ENTER THE STRING = ";
gets(a);
for(int i=0;i<=strlen(a);i++)
{
if(a[i]==' ')
{
wc++;
}
}
cout<<"NUMBER OF WORDS IN THE STRING ARE = "<<wc;
getch();
}
OUTPUT :
PROGRAM NO. 3
#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
void main()
{
char a[20];
int wc=0;
clrscr();
cout<<"Enter the paragraph = ";
gets(a);
for(int i=0;i<=strlen(a);i++)
{
if(a[i]=='.')
{
wc++;
}
}
cout<<" no of lines in paragraph are "<<wc;
getch();
}
OUTPUT :
PROGRAM NO 4.
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
char str[30],ch;
int count=0;
clrscr();
cout<<"Enter the string = ";
gets(str);
cout<<"Enter the character u want to find how many times it comes in a string = ";
cin>>ch;
for(int i=0;i<=strlen(str);i++)
{
if(str[i]==ch)
{
count++;
}
}
cout<<"number of times a word repeat"<<count;
getch();
}
OUTPUT:
PROGRAM NO 5.
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
char str[30],ch,b;
clrscr();
cout<<"Enter the string = ";
gets(str);
cout<<"Enter the character u want to replace with ";
cin>>ch;
cout<<"Enter new charcter =";
cin>>b;
for(int i=0;i<=strlen(str);i++)
{
if(str[i]==ch)
{
str[i]=b;
}
}
cout<<"new string is";
puts(str);
getch();
}
OUTPUT: