1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Counts each alpahbets occurs how many times

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

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    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. mangomiso

    mangomiso New Member

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

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    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. mangomiso

    mangomiso New Member

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

    mangomiso New Member

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

    mangomiso New Member

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

    pradeep Team Leader

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

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    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");
        }
    
    }
     
  9. aisha.ansari84

    aisha.ansari84 New Member

    Joined:
    Feb 13, 2008
    Messages:
    82
    Likes Received:
    1
    Trophy Points:
    0

Share This Page