Add more C code
This commit is contained in:
parent
07809d7d77
commit
21a17e33fa
16
C/helloworld.cpp
Executable file
16
C/helloworld.cpp
Executable file
@ -0,0 +1,16 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
|
||||
|
||||
for (const string& word : msg)
|
||||
{
|
||||
cout << word << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
30
C/histogram.cpp
Executable file
30
C/histogram.cpp
Executable file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
// Deklaration der Variablen
|
||||
int hist[26] = {};
|
||||
int i, k, c, count;
|
||||
int num = 0;
|
||||
|
||||
// Zeichen bis EOF einlesen (nur a-z werden berücksichtigt)
|
||||
// EOF wird im Terminal mit CTRL-D eingegeben!
|
||||
while ((c = getchar()) != EOF) {
|
||||
if ((c>96) && (c<123)) {
|
||||
// Zähler für diesen Buchstaben erhöhen
|
||||
hist[c-97]++;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
// Histogramm ausgeben
|
||||
printf("\n");
|
||||
for (i=0; i<26; i++) {
|
||||
count = hist[i];
|
||||
if (count > 0) {
|
||||
printf("%c : %f\n",i+97, (count/(float)num)*100);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
31
C/histogram2.cpp
Executable file
31
C/histogram2.cpp
Executable file
@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
// Deklaration der Variablen
|
||||
int hist[26] = {};
|
||||
int i, k, c, count;
|
||||
|
||||
// Zeichen bis EOF einlesen (nur a-z werden berücksichtigt)
|
||||
// EOF wird im Terminal mit CTRL-D eingegeben!
|
||||
while ((c = getchar()) != EOF) {
|
||||
if ((c>96) && (c<123)) {
|
||||
// Zähler für diesen Buchstaben erhöhen
|
||||
hist[c-97]++;
|
||||
}
|
||||
}
|
||||
|
||||
// Histogramm ausgeben
|
||||
printf("\n");
|
||||
for (i=0; i<26; i++) {
|
||||
count = hist[i];
|
||||
if (count > 0) {
|
||||
printf("%c : ",i+97);
|
||||
for (k=0; k<count; k++)
|
||||
printf("*");
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user