Showing posts with label Count. Show all posts
Showing posts with label Count. Show all posts

C Program String Count Example

How to write a C Program String Count in C Programming Language ?


Solution For C Program :

Write the procedure , which is one of a sum , a product and a geometric average in the panel for the NxM elements are located on opposite diagonal and main diagonal . Remind ! Counting only odd elements !

Write the procedure , which is one of a sum , a product and a geometric average in the panel for the NxM elements are located on opposite diagonal and main diagonal . Remind ! Counting only odd elements !


Schreib die Prozedur, die zählt eine Summe, einen Produkt und einen geometrischen Durchschnitt in der Tafel NxM fur die Elemente befinden sich über gegenläufigen Diagonale und unter hauptsächlichen Diagonale. Erinner! Zähl nur für ungerade Elementen!


Solution For C Program :

//Schreib die Prozedur, die zählt eine Summe, einen Produkt und einen geometrischen Durchschnitt in der Tafel NxM fur die Elemente befinden sich über gegenläufigen Diagonale und unter hauptsächlichen Diagonale. Erinner! Zähl nur für ungerade Elementen!

void prozedur (int tafel[N][M])
{
int i=0,j=0,Summe=0,Produkt=1;
float Durchschnitt;
for(i;i<N;i++)
   for(j;j<M;j++)
      if(i>j && i<(N-1)-j && tafel[i][j]!=0)
         Summe+=tafel[i][j];
         Produkt*=tafel[i][j];
Durchschnitt=Summe/(N*M);
printf("Summe ergibt: %d Produkt ergibt: %d geometrischer Durchschnitt ergibt: %d,Summe,Produkt,Durchschnitt);
}

C Program Array NxM Elements Geometric/Arithmetic

How to Write a C Program for numbering the product of all real numbers listed in the array NxM elements,  or function counting the arithmetic average of all the numbers listed in the array NxM Elemental, for counting the geometric mean NxM array elements and for counting the arithmetic average above the main diagonal in the table NxM elements in C Programming Language ?


//Napisać procedurę liczącą iloczyn wszystkich liczb rzeczywistych znajdujących się w tablicy NxM elementowej.

Write procedure for numbering the product of all real numbers listed in the array NxM elements.



void iloczyn (int tablica[N][M])
{
 int i,j,iloczyn=0;
for(i=0;i<N;i++)
    for(j=0;j<M;j++)
       iloczyn*=tablica[i][j];
printf("Iloczyn liczb w tablicy wynosi: ",iloczyn);
}

//Napisać procedurę lub funkcję liczącą średnią arytmetyczną wszystkich liczb znajdujących się w tablicy NxM elementowej.

Write a procedure or function counting the arithmetic average of all the numbers listed in the array NxM Elemental



float srednia_aryt(int tablica[N][M])
{
int i,j,suma=0;
for(i=0;i<N;i++)
    for(j=0;j<M;j++)
       suma+=tablica[i][j];
return suma/N*M;
}

 //Napisać procedurę liczącą średnią geometryczną w tablicy NxM elementowej.

//Write procedure for counting the geometric mean NxM array elements.



float srednia_geo(int tablica[N][M])
{
int i,j,iloczyn=0;
for(i=0;i<N;i++)
    for(j=0;j<M;j++)
       iloczyn*=tablica[i][j];
return pow(iloczyn,NxM);
}

   //Napisać procedurę liczącą średnią arytmetyczną ponad główną przekątna w tablicy NxM elementowej.

Write procedure for counting the arithmetic average above the main diagonal in the table NxM elements.



float srednia_aryt(int tablica[N][M])
{
int i,j,suma=0;
for(i=0;i<N;i++)
    for(j=0;j<M;j++)
       if(i<j)
         suma+=tablica[i][j];
return suma/N*M;
}

C Program to Count Number of Lines in Input until Interrupted by CTRL + Z

How to write a C Program to Count Number of Lines in Input until Interrupted by CTRL + Z in C Programming Language ?

Solution For C Program :

/*C Program to Count Number of Lines in Input until Interrupted by CTRL + Z*/
#include<stdio.h>
void main()
{
int no_lines = 0;
char ch;
printf("\nPlease Enter the Data...\n");
while((ch = getchar()) != EOF)
if(ch == '\n')
++no_lines;
printf("\nThe Number of Lines Entered are : %d\n", no_lines);
}

You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

Returns: array of decoded values. [0] - count of values

How to write a C Program to Returns: array of decoded values.  [0] - count of values in C Programming Language ?


Solution:

#include <stdlib.h>
#include <string.h>

/* Returns: array of decoded values.  [0] - count of values */
int *decode(char *encoded) {
    int idx = 1;
    int maxlen = 8;
    char *token;
    char *delim = " :;,|";
    int *nums = malloc(maxlen * sizeof(int));

    /* Preserve the original string */
    encoded = strdup(encoded);

    token = strtok(encoded, delim);
    nums[1] = atoi(token);

    while (token = strtok(NULL, delim)) {
        if (idx >= maxlen) {
            maxlen += 8;
            nums = realloc(nums, maxlen * sizeof(int));
        }
        nums[++idx] = atoi(token);
    }

    nums[0] = idx;
    return nums;
}

Max count of chars, Max count of nums and Max count of signs

How to write a C Program to Maximum count of chars, Maximum count of numbers and Maximum count of signs in C Programming Language ?

This C Program to Max count of chars, Max count of nums and Max count of signs.

Solution:


  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main() {
  4.         int chars=0, nums=0, mchars=0, mnums=0, signs=0, msigns = 0, i;
  5.         char str[500];
  6.         puts("Input string:");
  7.         gets(str);
  8.         for (= 0; str[i]; i++) {
  9.                 if (str[i] >= '0' && str[i] <= '9') {
  10.                         nums++;
  11.                         if (chars > mchars) mchars = chars;
  12.                         if (signs > msigns) msigns = signs;
  13.                         chars = signs = 0;
  14.                 }
  15.                 else {
  16.                         if (nums > mnums) mnums = nums;
  17.                         nums = 0;
  18.                         if ((str[i] >= 'a' && str[i] <= 'z') ||
  19.                                 (str[i] >= 'A' && str[i] <= 'Z')) {
  20.                                 chars++;
  21.                                 if (signs > msigns) msigns = signs;
  22.                                 signs = 0;
  23.                         }
  24.                         else if (str[i] == '*' || str[i] == '+' || str[i] == '-'){
  25.                                 signs++;
  26.                                 if (chars > mchars) mchars = chars;
  27.                                 chars = 0;
  28.                         }
  29.                         else {
  30.                                 if (chars > mchars) mchars = chars;
  31.                                 if (signs > msigns) msigns = signs;
  32.                         }
  33.                 }
  34.         }
  35.         if (nums > mnums) mnums = nums;
  36.         if (chars > mchars) mchars = chars;
  37.         if (signs > msigns) msigns = signs;
  38.         printf("Max count of chars: %d\nMax count of nums: %d\nMax count of signs: %d\n", mchars, mnums, msigns);
  39.         printf("Is chars count bigger than signs count: ");     printf(mchars > msigns ? "true" : "false");
  40.         _getch();
  41. }

C Program to Count Vowels, Consonants and Spaces in a string

C Program to count vowels, consonants and spaces in a string in C Programming Language ?

This C Program to Count Vowels, Consonants and Spaces in a string.
In this C Program the Sentence is Entered by the User and the C Program then Count Vowels, Consonants and Spaces in a String.

To Find:
  1. Total number of vowels entered.
  2. Total number of consonants entered.
  3. Total number of spaces entered.

Solution:

  1. #include<stdio.h>
  2. main()
  3. {
  4. int i,cons=0,vow=0,sp=0;
  5. char a[100];
  6. printf("Enter the sentence\n");
  7. gets(a);
  8. for(i=0;a[i]!='\0';i++)
  9. {
  10. if(a[i]=='a'||a[i]=='A')
  11. vow=vow+1;
  12. else if(a[i]=='e'||a[i]=='E')
  13. vow=vow+1;
  14. else if(a[i]=='i'||a[i]=='I')
  15. vow=vow+1;
  16. else if(a[i]=='o'||a[i]=='O')
  17. vow=vow+1;
  18. else if(a[i]=='u'||a[i]=='U')
  19. vow=vow+1;
  20. else if(a[i]==' ')
  21. sp=sp+1;
  22. else
  23. cons=cons+1;
  24. }
  25. printf("Total number of vowels entered = %d\n",vow);
  26. printf("Total number of consonants entered = %d\n",cons);
  27. printf("Total number of spaces entered = %d\n",sp);
  28. }

C Program to count number of sentences words and letters in a paragraph

How to write a C Program to count number of sentences words and letters in a paragraph in C Programming Language ?

This C Program to count number of sentences words and letters in a paragraph.

Solution:

  1. #include<stdio.h>
  2. main()
  3. {
  4.         char ch[150];
  5.         int i,c=0,c1=0,c2=0;
  6.         printf("Enter a Paragraph \n");
  7.         gets(ch);
  8.         for(i=0;ch[i]!='\0';i++)
  9.         {
  10.                 if(ch[i]=='.'||ch[i]=='!'||ch[i]=='?')
  11.                 {       c++;
  12.                         c1++;
  13.                 }
  14.                 else if(ch[i]==' '||ch[i]==',')
  15.                         c1++;
  16.                 else if(ch[i]>65&&ch[i]<123)
  17.                         c2++;
  18.         }
  19.         printf("\nNumber of letters = %d \nNumber of words=%d ",c2,c1);
  20.         printf("\nNumber of Sentences = %d\n",c);
  21. }

Un-sortiertes Array and Sortiertes Array

How to write a C Program Count Sort Calculate Counts / Un-sortiertes Array and Sortiertes Array in C Programming Language ?


Solution:


  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "input_blatt01.h"
  4.  
  5. int MAX_LAENGE = 1000;
  6. int MAX_VALUE = 100;
  7. int i,k,j;
  8. void count_sort_calculate_counts(int input_array[], int len, int count_array[])
  9. {
  10.     for (i=0; i<len;i++)
  11.     {
  12.         count_array[i] = 0;
  13.     }
  14.     for (j=0; j<len;j++)
  15.     {
  16.         count_array[input_array[j]] = count_array[input_array[j]] + 1;
  17.     }
  18. }
  19.  
  20. void count_sort_write_output_array(int output_array[], int len, int count_array[])
  21. {
  22.     k=0;
  23.     for (j=0;j<len;j++)
  24.     {
  25.         for (i=0; i<count_array[j]; i++)
  26.         {
  27.             output_array[k] = j;
  28.             k = k + 1;
  29.         }
  30.     }
  31. }
  32.  
  33.  
  34.  
  35. int main(int argc, char *argv[]) {
  36.  
  37.     if (argc < 2){
  38.         printf("Aufruf: %s <Dateiname>\n", argv[0]);
  39.         printf("Beispiel: %s zahlen.txt\n", argv[0]);
  40.         exit(1);
  41.     }
  42.  
  43.     char *filename = argv[1];
  44.    
  45.     int input_array[MAX_LAENGE];  
  46.     int len = read_array_from_file(input_array, MAX_LAENGE, filename);
  47.  
  48.     printf("Unsortiertes Array:");
  49.     print_array(input_array, len);
  50.     int count_array[MAX_LAENGE];
  51.     int output_array[MAX_LAENGE];
  52.     count_sort_calculate_counts(input_array, len, count_array);
  53.     count_sort_write_output_array(output_array, len, count_array);
  54.  
  55.     printf("Sortiertes Array:");
  56.     print_array(output_array, len);
  57.  
  58.     return 0;
  59. }