Új hozzászólás Aktív témák
-
válasz
rothkrisz
#482
üzenetére
Hali!
A progi CodeBlocksban íródott. Bár írtad, hogy most kezdtél C-ben írni, de ennak ellenére úgy írtam, hogy legyen bent valami "újdonság" is, ami hasznos. Nézd át, ha valami nem tiszta írj.
Fire.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char str[255];
unsigned char ndx[10];
int i,j,maxndx;
for(i=0;i<sizeof(ndx);ndx[i]=0, i++);
printf("Enter numbers (0-9): ");
gets(str);
for (i=0;i<strlen(str);i++) {
if (str[i]<'0' || str[i]>'9') {
printf("Illegal char found, skipped.. -> %c\n",str[i]);
continue;
};
ndx[str[i] & 0x0f]++;
}
//Horizontal
for(i=0;i<sizeof(ndx);i++) {
printf("\n%c ",i+'0');
for (j=ndx[i];j>0;j--) { printf("*"); }
}
printf("\n\n\n");
//Vertical
for(i=0, maxndx=0;i<sizeof(ndx);i++) {
maxndx=ndx[i]>=maxndx ? ndx[i] : maxndx;
}
for(;maxndx>0;maxndx--) {
for(i=0;i<sizeof(ndx);i++) {
ndx[i]<maxndx ? printf(" ") : printf("*");
}
printf("\n");
}
for(i=0;i<sizeof(ndx);printf("%c",'0'+i),i++);
printf("\n");
return 0;
}
Új hozzászólás Aktív témák
● olvasd el a téma összefoglalót!
● ha kódot szúrsz be, használd a PROGRAMKÓD formázási funkciót!
- BESZÁMÍTÁS! MSI B450M R5 5500 8GB DDR4 250GB SSD GTX 1050Ti 4GB Zalman S2 TG DeepCool 400W
- BESZÁMÍTÁS! MSI Thin GF63 15,6 FHD Gamer notebook-i5 11400H 16GB DDR4 512GB SSD RTX 3050 Ti 4GB W11
- Apple iPhone 15 Pro 128GB, Kártyafüggetlen, 1 Év Garanciával
- Cudy LT500D Dual Band 4G/LTE Wi-Fi router / 12 hó jótállás
- AKCIÓ! Apple Watch Ultra 2 49mm Cellular okosóra garanciával hibátlan működéssel
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Central PC számítógép és laptop szerviz - Pécs
Város: Pécs

