Posts

Showing posts from February, 2020

Checking the number of letters repeated in a word.

#include <stdio.h> #include <string.h> void main () { int i , count = 0 ; char c , str [ 100 ]; printf ( "Enter a sentence\n" ); scanf("%c",&str) ; printf ( "Enter a character to know it's repetance in sentence\n" ); scanf ( "%c" ,& c ); for ( i = 0 ; i < strlen ( str ); i ++) { if ( str [ i ]== c ) { count ++; } } printf ( "Letter %c repeated %d times\n" , c , count ); getch(); } Explanation: This program starts with initializing : str[100]  → To store  string with length of 100  which means it can store  100 letters i  →Used as  helping variable count → To store  number of  times a letter is repeated in a given string  and is initilized to  0. c  →Used  to store required letter printf("Enter a sentence\n"); scanf("%c",&str); Takes string from user. printf("Enter a character to know it's repetance in sentence\n"); sc...