Write a program to input a text string and count the length of it using get() and put().
#include<iostream.h>
#include<conio.h>
main()
{
int count = 0;
char c;
cout<< "Input text\n";
cin.get(c);
while(c != '\n')
{
cout.put(c);
count ++;
cin.get(c);
}
cout <<"\nNumber of characters = "<< count << "\n";
getch( );
return 0;
}
OUTPUT:
Input text: halim
Number of characters= 5
#include<iostream.h>
#include<conio.h>
main()
{
int count = 0;
char c;
cout<< "Input text\n";
cin.get(c);
while(c != '\n')
{
cout.put(c);
count ++;
cin.get(c);
}
cout <<"\nNumber of characters = "<< count << "\n";
getch( );
return 0;
}
OUTPUT:
Input text: halim
Number of characters= 5
No comments:
Post a Comment