Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- int char_occurence(char s[], char c) {
- int ct=0;
- for(int i=0;i<strlen(s);i++)
- if (s[i]==c)
- ct++;
- return ct;
- }
- int valid_triangle(float a, float b, float c) {
- if (a<0&&b<0&&c<0)
- return 0;
- if (a+b<c)
- return 0;
- if (b+c<a)
- return 0;
- if (a+c<b)
- return 0;
- }
- double function_value(double f[], double x, int n) {
- double sum=0;
- for (int i=0;i<n;i++) {
- sum+=f[i]*pow(x,i);
- printf("%f\n", sum);
- }
- return sum;
- }
- void function_derivative(double f_init[], double f_final[], int n) {
- for(int i=0;i<n;i++) {
- f_final[i]=i*f_init[i];
- }
- return;
- }
- int main()
- {
- char s[50],c;
- double f[3]={2,4,6},x=3,n=5;
- double f_init[5]={3,7,2,6,8},f_final[5];
- function_derivative(f_init,f_final,n);
- printf("Function's derivative coeffs are:");
- for (int i=0;i<n;i++)
- printf("%f ", f_final[i]);
- printf("The final sum is %f", function_value(f,x,n));
- gets(s);
- scanf("%c", &c);
- printf("Function found character \"%c\" %d times in the string", c, char_occurence(s,c));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement