Pages

Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Tuesday, February 17, 2015

C Program to Count no of words in a string

C++ Program to Count no. of words in a string

#include<iostream.h>
#include<conio.h>
#include<stdio.h>

void main()
{
clrscr();
char a[20];
int i,count=0;
cout<<"Enter a string:";
gets(a);
for(i=0;a[i]!=
Read more »

C program to read a string and print it in alphabetical order


C program to read a string and print it in alphabetical order

#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
int i,j,n,ch1,ch2;
char a[50],temp;
clrscr();
printf("Enter any string:");
scanf("%s",a);
n=strlen(a);

for(i=1;i<n;++i)
for(j=0;j<(n-i);++j)
{
ch1=a[j];
ch2=a[j+1];
if(ch1>ch2)
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}

printf("String after arranging %s",a);
getch();
}
Read more »

Monday, February 16, 2015

C Program to check whether a String is Palindrome or not

C++ Program to check whether a String is Palindrome or not

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int i,j,len,flag=1;
char a[20];
cout<<"Enter a string:";
cin>>a;

for(len=0;a[len]!=
Read more »