Answers for "how to count numbers in string c porgram"

C
1

count number of words in a string in c

/*
 * C Program to Count Number of Words in a given Text Or Sentence
 */
#include <stdio.h>
#include <string.h>
 
void main()
{
    char s[200];
    int count = 0, i;
 
    printf("Enter the string:n");
    scanf("%[^n]s", s);
    for (i = 0;s[i] != '';i++)
    {
        if (s[i] == ' ' && s[i+1] != ' ')
            count++;    
    }
    printf("Number of words in given string are: %dn", count + 1);
}
Posted by: Guest on June-21-2021
0

program in C to count total number of alphabets, digits and special characters in a string.

#include <stdio.h>
#include <string.h>
 
int main()
{
    char s[1000]; 
    int i,alphabets=0,digits=0,specialcharacters=0;
 
    printf("Enter  the string : ");
    gets(s);
     
    for(i=0;s[i];i++)  
    {
        if((s[i]>=65 && s[i]<=90)|| (s[i]>=97 && s[i]<=122) )
          alphabets++;
        else if(s[i]>=48 && s[i]<=57)
         digits++;
        else
         specialcharacters++;
 
 	}
 	
     
    printf("Alphabets = %dn",alphabets);
    printf("Digits = %dn",digits);
    printf("Special characters = %d", specialcharacters);
    
 
    return 0;
}
Posted by: Guest on September-08-2021

Code answers related to "how to count numbers in string c porgram"

Code answers related to "C"

Browse Popular Code Answers by Language