Program No. 1

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 10

PROGRAM NO.

AIM:- WAP TO FIND LENGTH OF STRING INCLUDING SPACES .

#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

AIM:- WAP TO COUNT NUMBER OF WORDS WITH IN A STRING .

#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

AIM:- WAP TO COUNT NUMBER OF LINES IN THE PARAGRAPH .

#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.

AIM:- WAP TO FIND NUMBER OF TIMES A WORD COME IN STRING.

#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.

AIM:- WAP TO REPLACE A WORD WITH IN STRING WITH ANOTHER


WORD .

#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:

You might also like