Counts each alpahbets occurs how many times

S k's Avatar author of Counts each alpahbets occurs how many times
This is an article on Counts each alpahbets occurs how many times in C.
This is the code I wrote in my college days and dont quote me on this if something does not go as expected.

Code: C
#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();
}
0
mangomiso's Avatar, Join Date: Nov 2006
Light Poster
can u pliz show me how to do a pseudocode or a C++ program for finding a prime number
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Here is the C program to find a prime number.

Code: C
#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");
}
0
mangomiso's Avatar, Join Date: Nov 2006
Light Poster
that flag what does it mean? how can i represent it in C++ not in C?
0
mangomiso's Avatar, Join Date: Nov 2006
Light Poster
how do i write a C++ program to
0
mangomiso's Avatar, Join Date: Nov 2006
Light Poster
how do i write a C++ program to draw a diamond of stars ie *
***
***** ?
***
*
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Setting is the flag to 0 means that the number is not a prime number. You can set it to boolean also.
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
To print stars

Code: C
#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");
    }

}
0
aisha.ansari84's Avatar, Join Date: Feb 2008
Contributor
nice one