Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############### TABLICA WSKAŹNIKÓW #########################
- #include <stdio.h>
- #include <stdlib.h>
- int sum(int a, int b){
- return a + b;}
- int substract(int a, int b){
- return a - b;}
- int multi (int a, int b){
- return a * b;}
- int (*p[3])(int a, int b);
- int main()
- {
- int result;
- p[0] = sum;
- p[1] = substract;
- p[2] = multi;
- result = (*p[2])(4,2);
- printf("%d", result);
- return 0;
- }
- ############### TABLICE DWUWYMIAROWE #########################
- #include <stdio.h>
- #include <stdlib.h>
- int jedynki(int liczba){
- int count = 0;
- while (liczba){
- liczba &= liczba - 1;
- count++;
- }
- return count;
- }
- int main()
- {
- int wiersze;
- int kolumny;
- unsigned int currentMax = 0;
- int row;
- printf("Podjac liczbê wierszy:\n");
- scanf("%d", &wiersze);
- printf("Podaj liczbê kolumn:\n");
- scanf("%d", &kolumny);
- int** xy;
- xy = (int**)malloc(wiersze*sizeof(unsigned int));
- for (int i = 0; i < wiersze; i++){
- xy[i] = (int*)malloc(2 * sizeof(unsigned int));
- }
- for (int i = 0; i < wiersze; i++){
- printf("Uzupe³nij wiersz");
- for (int j = 0; j < kolumny; j++){
- scanf("%d", &(xy[i][j]));
- }
- }
- printf("Tablica zostanie wydrukowana");
- for (int i = 0; i < wiersze; i++){
- for (int j = 0; j < kolumny; j++){
- printf("%d", xy[i][j]);
- }
- printf("\n");
- }
- for (int i = 0; i<wiersze; i++){
- unsigned int jedyneczki = 0;
- for (int j = 0; j<kolumny; j++){
- jedyneczki += jedynki(xy[i][j]);
- }
- if (jedyneczki > currentMax){
- currentMax = jedyneczki;
- row = i;
- }
- }
- printf("%d", currentMax);
- for (int j = 0; j<kolumny; j++){
- printf("%d", xy[row][j]);
- }
- free(xy);
- return 0;
- }
- ################ DYNAMICZNE TABLICE JEDNOWYMIAROWE #####################
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int N;
- printf("Podaj wielkoϾ tablicy");
- scanf("%d", &N);
- int *x = (int*)malloc(N*sizeof(int));
- for (int i = 0; i < N; i++){
- scanf("%d", &(x[i]));
- }
- printf("drukowanie tablicy");
- for (int i = 0; i<N; i++){
- printf("%d\n", x[i]);
- }
- }
- ############## CZYTANIE WORD BY WORD ###################
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- char costam[30];
- FILE *fpointer = fopen("tekst.txt", "ra");
- while (!feof(fpointer)){
- fscanf(fpointer, "%s", costam);
- printf("Next word is: %s\n", costam);
- }
- return 0;
- }
- ############# CZYTANIE CHAR BY CHAR ###################
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- char ch;
- FILE *fpointer = fopen("tekst.txt", "ra");
- while (!feof(fpointer)){
- ch = fgetc(fpointer);
- printf("Next sign is: \"%c\"\n", ch);
- }
- return 0;
- }
- ############## CZYTANIE LINE BY LINE ##################
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- char line[255];
- FILE *fpointer = fopen("tekst.txt", "ra");
- while (!feof(fpointer)){
- fgets(line, 255, fpointer);
- printf("Next line is: %s\n", line);
- }
- fclose(fpointer);
- return 0;
- }
- ############## APPENDING AND READING ####################
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- char line[255];
- FILE *fpointer = fopen("tekst.txt", "a+");
- fprintf(fpointer, "\nuwaga dodaje linie");
- fseek(fpointer, 0, 0);
- while (!feof(fpointer)){
- fgets(line, 255, fpointer);
- printf("Next line is: %s\n", line);
- }
- fclose(fpointer);
- return 0;
- }
- ############ SZESNASTKOWY ##############
- #include <stdio.h>
- #include <stdlib.h>
- void heksa(int liczba, char* heksadecymalna){
- char szesnastkowa[20];
- char tablica[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
- int reszta;
- int index = 0;
- while(liczba != 0){
- reszta = liczba % 16;
- liczba = liczba / 16;
- szesnastkowa[index] = tablica[reszta];
- index++;
- }
- int heksaindex = 0;
- int nowy_index = index - 1;
- for (nowy_index; nowy_index >= 0; nowy_index--){
- heksadecymalna[heksaindex] = szesnastkowa[nowy_index];
- heksaindex++;
- }
- }
- int main()
- {
- char arr[15];
- heksa(375098, arr);
- printf("Konwersja: %s\n", arr);
- return 0;
- }
- ############ TABLICA STRUKTUR ############
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- FILE *fpointer = fopen("tekst.txt", "r");
- struct Student{
- int age;
- };
- struct Student s[5];
- int counter = 0;
- int age1;
- while (!feof(fpointer)){
- fscanf(fpointer, "%d\n", &age1);
- s[counter].age = age1;
- counter++;
- };
- printf("%d", s[3].age);
- return 0;
- }
- ########### NOTATKI ##################
- - przekazywanie stringu do struktury
- ctrcpy(student1.name, "Jim");
- - uzyskiwanie adresu
- printf("%p", &age);
- - storing pointer variable
- int *pAge = &age;
- - dereferencing pointer
- printf("%d", *pAge);
- - wprowadzanie stałej
- const int NUM = 5;
- -getting double
- scanf("%lf", &gpa);
- - getting string
- scanf("%s", name);
- - getting line of text
- scanf(name, 20, stdin);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement