# Counts each alpahbets occurs how many times

Discussion in 'C' started by pradeep, Oct 2, 2006.

Joined:
Apr 4, 2005
Messages:
1,646
86
Trophy Points:
0
Occupation:
Programmer
Location:
Kolkata, India
This is the code I wrote in my college days and dont quote me on this if something does not go as expected.

Code:
```#include<stdio.h>
#include<ctype.h>
#include<conio.h>

void main()
{
int c,i,letter[26];
for(i=0;i<26;i++)
letter[i]=0;
while((c=getchar())!='~')
{
if(isupper(c))
++letter[c-'A'];
if(islower(c))
++letter[c-'a'];
}
for(i=0;i<26;i++)
{
if(i%6==0)
printf("\n");
printf("%5c %4d",'A'+i,letter[i]);
}
printf("\n\n");
getch();
}```

2. ### mangomisoNew Member

Joined:
Nov 22, 2006
Messages:
8
0
Trophy Points:
0
can u pliz show me how to do a pseudocode or a C++ program for finding a prime number

Joined:
Apr 4, 2005
Messages:
1,646
86
Trophy Points:
0
Occupation:
Programmer
Location:
Kolkata, India
Here is the C program to find a prime number.

Code:
```#include <stdio.h>

void main(void)
{
unsigned int n,half,i,flag=1;

printf("Enter the number : ");
scanf("%d",&n);

half = n/2;

for(i=2;i<=half;i++)
{
if(n%i==0)
flag = 0;
}

if(flag)
printf("The number is a prime number");
else
printf("The number is not a prime number");
}```

4. ### mangomisoNew Member

Joined:
Nov 22, 2006
Messages:
8
0
Trophy Points:
0
that flag what does it mean? how can i represent it in C++ not in C?

5. ### mangomisoNew Member

Joined:
Nov 22, 2006
Messages:
8
0
Trophy Points:
0
how do i write a C++ program to

6. ### mangomisoNew Member

Joined:
Nov 22, 2006
Messages:
8
0
Trophy Points:
0
how do i write a C++ program to draw a diamond of stars ie *
***
***** ?
***
*

Joined:
Apr 4, 2005
Messages:
1,646
86
Trophy Points:
0
Occupation:
Programmer
Location:
Kolkata, India
Setting is the flag to 0 means that the number is not a prime number. You can set it to boolean also.

Joined:
Apr 4, 2005
Messages:
1,646
86
Trophy Points:
0
Occupation:
Programmer
Location:
Kolkata, India
To print stars

Code:
```#include <stdio.h>

void main(void)
{
unsigned int n,j,i;
/* n has to be a even no. */

printf("Enter the number of rows : ");
scanf("%d",&n);

for(i=0;i<n/2;i++)
{
for(j=0;j<i;j++)
printf("*");
printf("\n");
}

for(i=n/2;i>0;i--)
{
for(j=0;j<i;j++)
printf("*");
printf("\n");
}

}```

Joined:
Feb 13, 2008
Messages:
82