برنامه ای که 10 جمله را خوانده تعداد حروف، ارقام و کلمات را تعیین کند
جمعه 29 شهریور 1392 7:47 AM
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
int words,alphabets,numbers;
void getcount(char s[])
{
int state=0;
char chars[]=" !()*+,./:;<=>?[\\]^`{}~";
for (int pos=0;s[pos];pos++)
{
if (((s[pos]>='A') && (s[pos]<='Z'))
|| ((s[pos]>='a') && (s[pos]<='z')))
{
state=1;
alphabets++;
}
else if ((s[pos]>='0') && (s[pos]<='9'))
{
state=1;
numbers++;
}
else
for (int chpos=0;chars[chpos];chpos++)
if (chars[chpos]==s[pos])
{
if (state)
words++;
state=0;
break;
}
}
if (state)
words++;
}
int main()
{
int i;
char s[500];
clrscr();
words=0;
alphabets=0;
numbers=0;
for (i=0;i<10;i++)
{
cout << "Please enter a text #" << (i+1) << " : " << endl;
gets(s);
getcount(s);
}
cout << endl << "Count of words = " << words << endl;
cout << endl << "Count of alphabet chars = " << alphabets << endl;
cout << endl << "Count of numeric chars = " << numbers << endl;
cout << endl << "Press any key to continue." << endl;
getch();
return 0;
}
Seyyed.Reza.Hashemian@Gmail.Com
دوستانی که سوالی دارند یا مایل به تماس هستند می توانند از اطلاعات بالا استفاده نمایند.
اگر هم تایپکی زدید و احتیاج به پاسخگویی سریع داشتید اطلاع دهید