• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Apr 24th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #define _CRT_SECURE_NO_WARNINGS
2.
3. #include <stdio.h>
4. #include <conio.h>
5. #include <cstdlib>
6. #include <string>
7.
8. int evenNumber(int m);
9. int compareString(char *buff1, char *buff2);
10. int **dodajMacierz(int **tab1, int **tab2, int n);
11. int **wypelnijMacierz(int **macierz, int n);
12. float newtonRaphson(float epsilon, float liczba);
13.
14. int main()
15. {
16.     /*
18.     float a, b, c, delta;
19.
20.     printf("Podaj a, b i c ");
21.     scanf("%f %f %f", &a, &b, &c);
22.
23.     delta = b * b - 4 * a * c;
24.
25.     if (delta > 0)
26.     {
27.         printf("x1 = %f, x2 = %f", ( - b - sqrt(delta)) / (2 * a), (-b + sqrt(delta)) /( 2 * a));
28.     }
29.     else
30.     {
31.         if (delta == 0)
32.             printf("x0 = %f", -b / 2*a);
33.
34.         else
35.             printf("Brak pierwistakow");
36.     }
37.
38.
39.
41.     int m;
42.
43.     printf("Podaj lizbe calkowita: ");
44.     scanf("%d", &m);
45.     printf("Liczba %d, %d", m, evenNumber(m));
46.
47.
48.
50.     int a, b, pomoc, *wskaznik;
51.     printf("Podaj liczby a i b: ");
52.     scanf("%d %d", &a, &b);
53.     printf("Adres a = %d, adres b = %d\n", &a, &b);
54.     wskaznik = &a;
55.     pomoc = b;
56.     b = *wskaznik;
57.     a = pomoc;
58.     printf("a = %d, b = %d", a, b);
59.
60.
61.
63.     char *buff1, *buff2;
64.
65.     buff1 = (char*)malloc(sizeof(int)*256);
66.     buff2 = (char*)malloc(sizeof(int)*256);
67.
68.     FILE *s = NULL;
69.     s = fopen("file1.txt", "r");
70.     fscanf(s, "%s", buff1);
71.     fclose(s);
72.
73.     s = NULL;
74.     s = fopen("file2.txt", "r");
75.     fscanf(s, "%s", buff2);
76.     fclose(s);
77.
78.     if (compareString(buff1, buff2) == 1)
79.         printf("Ciagi znakow sa takie same");
80.
81.     else
82.         printf("Ciagi znakow sa rozne");
83.
84.     fclose(s);
85.
86.
87.
89.     int **tab1, **tab2, n;
90.
91.     printf("Podaj wymiar macierzy: ");
92.     scanf("%d", &n);
93.
94.     tab1 = (int**)malloc(sizeof(int)*n);
95.     tab2 = (int**)malloc(sizeof(int)*n);
96.
97.     for (int i = 0; i < n; i++)
98.         {
99.             tab1[i] = (int*)malloc(sizeof(int)*n);
100.             tab2[i] = (int*)malloc(sizeof(int)*n);
101.         }
102.
103.     printf("Wypelnij pierwsza macierz\n");
104.     wypelnijMacierz(tab1, n);
105.
106.     printf("Wypelnij druga macierz\n");
107.     wypelnijMacierz(tab2, n);
108.
109.     int **macierz = dodajMacierz(tab1, tab2, n);
110.
111.     for (int i = 0; i < n; i++)
112.     {
113.         for (int j = 0; j < n; j++)
114.             printf("%d\t", macierz[i][j]);
115.         printf("\n");
116.     }
117.     */
118.
119.
120.
122.
123.     float liczba, epsilon;
124.     printf("Podaj liczbe podpierwiastkowa oraz dokladnosc pierwiastka ");
125.     scanf("%f %f", &liczba, &epsilon);
126.
127.     printf("Pierwiatek z liczby %f z przyblizeniem %f = %f", liczba, epsilon, newtonRaphson(epsilon, liczba));
128.
129.     _getch();
130.     return 0;
131. }
132.
133. int evenNumber(int m)
134. {
135.     if (m % 2 == 0) return 0;
136.     else return 1;
137. }
138.
139. int compareString(char *buff1, char *buff2)
140. {
141.     int i = 0, Bool = 0;
142.
143.     do
144.     {
145.         if (buff1[i] == buff2[i]) Bool = 1;
146.         else Bool = 0;
147.
148.         i++;
149.
150.     } while ((buff1[i] != '\0') || (buff2[i] != '\0') || (Bool == 1));
151.
152.     if (Bool == 1) return 1;
153.     else return 0;
154. }
155.
156. int **wypelnijMacierz(int **macierz, int n)
157. {
158.     for (int i = 0; i < n; i++)
159.     {
160.         for (int j = 0; j < n; j++)
161.         {
162.             printf("Podaj A[%d][%d] ", i, j);
163.             scanf("%d", &macierz[i][j]);
164.         }
165.     }
166.
167.     return macierz;
168. }
169.
170. int **dodajMacierz(int **mac1, int **mac2, int n)
171. {
172.     for (int i = 0; i < n; i++)
173.     {
174.         for (int j = 0; j < n; j++)
175.             mac1[i][j] = mac1[i][j] + mac2[i][j];
176.     }
177.
178.     return mac1;
179. }
180.
181. float newtonRaphson(float epsilon, float liczba)
182. {
183.     float a = 1, b = liczba;
184.
185.     while (abs(a - b) >= epsilon)
186.     {
187.         a = (a + b) / 2;
188.         b = liczba / a;
189.     }
190.
191.     return a;
192. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top