Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C Compiler.
  4. Code, Compile, Run and Debug C program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <time.h>
  11.  
  12. int main( ) // program kopiowania z stdin na stdout
  13. {
  14. srand(time(NULL));
  15. int c,d,i,j;
  16. d=10;
  17. char tab[d];
  18. i=0;
  19. // zad4
  20. // for(i=0; i<d-1 && (c = getchar()) != EOF && c!='\n'; i++)
  21. // tab[i]=c;
  22. // if(c=='\n'){
  23. // tab[i] = c;
  24. // i++;
  25. // }
  26. //zad 5
  27. for(i=0; i<d-1; i++)
  28. tab[i]= 'a' + rand()%('z'-'a'+1);
  29.  
  30.  
  31. // koniec zad 5
  32. tab[i]='\0';
  33. printf("Tablica z wpisanych liczb: \n");
  34. i=0;
  35. while(tab[i]!='\0'){
  36. printf("\t znak: jako znak %c, jako liczba %d\n", tab[i++], tab[i]);
  37. }
  38. return 0;
  39. }
  40.  
  41. // PLIK 2
  42. #include <stdio.h>
  43. int main() // program zliczania cyfr i innych znaków we wczytywanym napisie
  44. {
  45. int i, nwhite=0, nother=0; // zmienne do zliczania
  46. int ndigit[10]={0}; // w tym tablica inicjowana zerami
  47.  
  48. int c; // c definiowane jako int bo EOF niekoniecznie jest znakiem
  49. while( (c = getchar()) != EOF) { // wczytywanie kolejnych znaków aż do EOF
  50. if(c>=48 && c<=57){
  51. ndigit[c-'0']++;
  52. printf("%c, %d, %d\n", c, c-'0', ndigit[c-'0']);
  53.  
  54. }
  55. else if(c==10 || c==32 || c==9){
  56. nwhite++;
  57. }
  58. else{
  59. nother++;
  60. }
  61.  
  62. }
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement