C program to find the frequency of characters in a string

Program : - 

#include<stdio.h>
#include<conio.h>
void main()
{
       char c[1000],ch;
       int i,count=0;
       printf("Enter a string: ");
       gets(c);
       printf("Enter a character to find frequency: ");
       scanf("%c",&ch);
       for(i=0;c[i]!='\0';++i)
       {
               if(ch==c[i])
               ++count;
       }
       printf("Frequency of %c = %d", ch, count);
       getch();
}

 

Output : -

Enter a string: This website is awesome.
Enter a character to find frequency: e
Frequency of e = 4

 


Make a reverse half piramid using numbers

5 5 5 5 5 4 4 4 4 3 3 3 2 2 1



Program : -

#include<stdio.h> #include<conio.h> int main() { int i,j,rows; printf("Enter the number of rows :"); scanf("%d",&rows); for(i=rows;i>=1;--i) { for(j=1;j<=i;++j) { printf("%d ",i); } printf("\n"); } getch(); }

Output : -


Enter the number of rows :5

5 5 5 5 5 4 4 4 4 3 3 3 2 2 1

C Program to print inverted half pyramid using number

1 2 3 4 5 1 2 3 4 1 2 3 1 2 1




Program : -

#include<stdio.h> #include<conio.h> int main() { int i,j,rows; printf("Enter the number of rows :"); scanf("%d",&rows); for(i=rows;i>=1;--i) { for(j=1;j<=i;++j) { printf("%d ",j); } printf("\n"); } getch(); }

Output : -


Enter the number of rows :5

1 2 3 4 5 1 2 3 4 1 2 3 1 2 1

Write a C Program to print inverted half pyramid using Number

* * * * * * * * * * * * * * *



Program : -



#include<stdio.h> #include<conio.h> void main() { int i,j,rows; printf("Enter the number of rows : "); scanf("%d",&rows); for(i=rows;i>=1;--i) { for(j=1;j<=i;++j) { printf("* "); } printf("\n"); } getch(); }



Output : -

Enter the number of rows : 5
* * * * * * * * * * * * * * *

Make a alphabet pattern

A B B
C C C D D D D E E E E E


Program : -


#include<stdio.h> #include<conio.h> void main() { int i,j; char input,temp='A'; printf("Enter uppercase character you want in triangle at last row: "); scanf("%c",&input); for(i=1;i<=(input-'A'+1);++i) { for(j=1;j<=i;++j) printf("%c",temp); ++temp; printf("\n"); } getch(); }


Output : -

Enter uppercase character you want in triangle at last row: E
A B B C C C D D D D E E E E E