Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/articles/c-tutorials/)
-   -   Counts each alpahbets occurs how many times (http://www.go4expert.com/articles/counts-alpahbets-occurs-times-t1518/)

 S k 2Oct2006 22:21

Counts each alpahbets occurs how many times

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();}`

 mangomiso 22Nov2006 17:45

Re: Counts each alpahbets occurs how many times

can u pliz show me how to do a pseudocode or a C++ program for finding a prime number

Re: Counts each alpahbets occurs how many times

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");}`

 mangomiso 22Nov2006 18:04

Re: Counts each alpahbets occurs how many times

that flag what does it mean? how can i represent it in C++ not in C?

 mangomiso 22Nov2006 18:10

Re: Counts each alpahbets occurs how many times

how do i write a C++ program to

 mangomiso 22Nov2006 18:11

Re: Counts each alpahbets occurs how many times

how do i write a C++ program to draw a diamond of stars ie *
***
***** ?
***
*

Re: Counts each alpahbets occurs how many times

Setting is the flag to 0 means that the number is not a prime number. You can set it to boolean also.

Re: Counts each alpahbets occurs how many times

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");    }}`

 aisha.ansari84 5Mar2008 18:44

Re: Counts each alpahbets occurs how many times

nice one

 All times are GMT +5.5. The time now is 20:03.