Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // uloha-4-1.c -- Tyzden 4 - Uloha 1
- // Michal Kovacik, 11.3.2014 07:01:57
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #define ABECEDA ('Z'-'A'+1)
- int main()
- {
- int histogram[ABECEDA], pismeno, i, j=1;
- char subor[1000];
- FILE *fr;
- scanf("%s", subor);
- if((fr=fopen(subor, "r"))==NULL)
- {
- printf("Subor sa nepodarilo otvorit\n");
- return 0;
- }
- putchar(' ');
- for (pismeno=0; pismeno<ABECEDA; pismeno++)
- {
- printf(" %c", (pismeno+'A'));
- }
- putchar('\n');
- do{
- for(i=0; i<ABECEDA; i++)
- histogram[i]=0;
- while((toupper(pismeno=getc(fr)))!=EOF && pismeno!='\n')
- if(isalpha(pismeno))
- {
- histogram[toupper(pismeno)-'A']++;
- }
- if(pismeno!=EOF)
- {
- printf("%d", j++);
- for(i=0; i<ABECEDA; i++)
- printf(" %2d", histogram[i]);
- putchar('\n');
- }
- } while(pismeno!=EOF);
- return 0;
- }
- // uloha-4-2.c -- Tyzden 4 - Uloha 2
- // Michal Kovacik, 11.3.2014 07:03:10
- #include <stdio.h>
- int parne(int x[], int pocetx, int y[])
- {
- int parne = 0, i;
- for (i = 0; i < pocetx; i++){
- if (!(x[i] % 2))
- y[parne++] = x[i];
- }
- return parne;
- }
- int main()
- {
- int x[7] = {4, 7, 1, 3, 2, 5, 6};
- int pocetx = 7;
- int y[7];
- int i, pocety = parne(x, pocetx, y);
- printf("pocety: %d\ny: {", pocety);
- for (i = 0; i < pocety; i++)
- {
- if (i > 0)
- printf(", ");
- printf("%d", y[i]);
- }
- printf("}\n");
- return 0;
- }
- // uloha-4-3.c -- Tyzden 4 - Uloha 3
- // Michal Kovacik, 11.3.2014 08:50:41
- #include <stdio.h>
- int nasobky(int x[], int pocetx, int y[], int k)
- {
- int i, j=0;
- if (k>=0){
- for(i=0; i<pocetx; i++){
- if(!k){
- if(k==x[i])
- y[j++]=x[i];
- }
- else if(!(x[i]%k))
- y[j++]=x[i];
- }
- }
- return j;
- }
- int main()
- {
- int x[10] = {4, 7, 10, 1, 3, 9, 2, 5, 8, 6};
- int pocetx = 10;
- int y[10];
- int i, pocety = nasobky(x, pocetx, y, 2);
- printf("pocety: %d\ny: {", pocety);
- for (i = 0; i < pocety; i++)
- {
- if (i > 0)
- printf(", ");
- printf("%d", y[i]);
- }
- printf("}\n");
- return 0;
- }
- // uloha-4-4.c -- Tyzden 4 - Uloha 4
- // Michal Kovacik, 11.3.2014 08:51:23
- #include <stdio.h>
- int delitele(int x[], int pocetx, int y[], int k)
- {
- int delitelov = 0, i;
- for (i = 0; i < pocetx; i++){
- if(!x[i]){
- if(k==x[i])
- y[delitelov++]=x[i];
- }
- else if (!(k % x[i]))
- y[delitelov++] = x[i];
- }
- return delitelov;
- }
- int main()
- {
- int x[10] = {4, 7, 10, 2, 3, 9, 6, 5, 8, 12};
- int pocetx = 10;
- int y[10];
- int i, pocety = delitele(x, pocetx, y, 24);
- printf("pocety: %d\ny: {", pocety);
- for (i = 0; i < pocety; i++)
- {
- if (i > 0)
- printf(", ");
- printf("%d", y[i]);
- }
- printf("}\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement