#include<math.h>#include<stdio.h>float fun (float num ){int s ;float n, t, pi ;
t =1; pi =0; n =1; s =1;while(t >= num){
pi = pi + t ;
n = n +2;
s =-s ;
t = s % n ;}
pi = pi *4;return pi ;}main(){float n1, n2 ;printf("Enter a float number: ");scanf("%f",&n1);
n2 =fun(n1);printf("%6.4f\n", n2);}
#include<stdio.h>#include<string.h>#define LEN 20 void fun (char a[],char b[],int n){}main(){char str1[LEN], str2[LEN];int n ;printf("Enter the string:\n");gets(str1);printf("Enter the position of the string deleted:");scanf("%d",&n);fun(str1, str2, n);printf("The new string is: %s\n", str2);NONO();}
解題思路: 本題是利用字符串拷貝和字符串連接來生成新的字符串。 參考答案:
void fun (char a[],char b[],int n){strncpy(b, a, n);
b[n]=0;strcat(b, a + n +1);}