Advertisement
Guest User

Probleme Lab 2

a guest
Feb 27th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5.  
  6. int char_occurence(char s[], char c) {
  7.     int ct=0;
  8.     for(int i=0;i<strlen(s);i++)
  9.     if (s[i]==c)
  10.         ct++;
  11.     return ct;
  12. }
  13.  
  14. int valid_triangle(float a, float b, float c) {
  15.     if (a<0&&b<0&&c<0)
  16.         return 0;
  17.     if (a+b<c)
  18.         return 0;
  19.     if (b+c<a)
  20.         return 0;
  21.     if (a+c<b)
  22.         return 0;
  23. }
  24.  
  25. double function_value(double f[], double x, int n) {
  26.     double sum=0;
  27.     for (int i=0;i<n;i++) {
  28.         sum+=f[i]*pow(x,i);
  29.         printf("%f\n", sum);
  30.     }
  31.     return sum;
  32. }
  33.  
  34. void function_derivative(double f_init[], double f_final[], int n) {
  35.     for(int i=0;i<n;i++) {
  36.         f_final[i]=i*f_init[i];
  37.     }
  38.     return;
  39. }
  40.  
  41. int main()
  42. {
  43.     char s[50],c;
  44.     double f[3]={2,4,6},x=3,n=5;
  45.     double f_init[5]={3,7,2,6,8},f_final[5];
  46.     function_derivative(f_init,f_final,n);
  47.     printf("Function's derivative coeffs are:");
  48.     for (int i=0;i<n;i++)
  49.         printf("%f ", f_final[i]);
  50.     printf("The final sum is %f", function_value(f,x,n));
  51.     gets(s);
  52.     scanf("%c", &c);
  53.     printf("Function found character \"%c\" %d times in the string", c, char_occurence(s,c));
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement