Welcome..!!

Please visit http://csprograms.in/ for more Computer Science programs.

Wednesday 14 March 2012

19. C++ program to find the length of a string.


# include <iostream>
# include <string>

int main()

{
char s1[25];
cout << “Enter the string:”;

cin > > str1;
cout < < “Strlen(str1): “< < strlen(str1) < < end1;
return 0;
}

18. C++ program to convert a string into upper-case or lower-case .


# include < iostream>
# include < string>
int main()
{
char str1 [30], temp[30];
cout < < “Enter the string:”;
cin > > str1;
strcpy ( temp, str1);
cout < < “strupr ( temp ) : “ < < strupr (temp) < < end1;
cout < < “strlwr (temp) : “ < < strlwr ( temp) < < end1;
return 0;
}

17. C++ program to compare strings.


# include < iostream>
# include < string>
int main()
{
char str1[30], str2 [30];
cout << “Enter string str1:”;
cin >> str1;
cout << “Enter string str2:”;
cin >> str2;
int status = strcmp ( str1 ,str2 );
cout < < “strcmp (str1, str2 ):”;
if (status = = 0)
cout < < “str1 < <” is greater than” << str2;
else
cout < < str1 < < “is less than” << str2;

return 0;

}

16. C++ program to concatenate strings.


# include < iostream>
# include < string >
int main()

{
char str1[50], str2 [35];
cout < < “Enter string str1;”;
cin >> str1;
cout < < “Enter string str2:”;
cin >> str2;
strcat(str1,str2);
cout < < “strcat (str1, str2 ) : “< < str1;
return 0;
}

15. C++ program to copy string.


# include < iostream>
# include < string>
int main()
{
char str1[30], str [30];
cout << “Enter the string:” ;
cin >> str1;
strcpy( str2, str1);
cout << “strcpy (str2, str1) : “< < str2;
return 0;
}

14. C++ program to reverse the string .


# include < iostream>
# include < string>
int main()
{
char str1[50], str2 [50];
cout << “Enter the string:” ;
cin >> str1;
str2 = strrev ( str1);
cout << “strrev (str1) : “< < str2;
return 0;
}

13. C++ program to find smallest among 'n' numbers.


#include <iostream>
int main()
{
int i,n,m;
cout <<"Enter the total number\n";
cin >>n;
cout <<"The total number of array is \n"<<n;
for(i=1;i<=n;i++)
cin >>a[i];
cout <<"the array is \n";
for(i=1;i<=n;i++)
cout <<"\n"<<a[i];

m = a[1];
for(i=2;i<=n;i++)
{
if(m>a[i])
s = a[i];
}
cout <<"smallest among 'n' number is \n"<< m;
return 0;
}