
第三题帮你做了
main() {int i,j; for(Ii=0;i<4;i++) {for(j=0;j<i;j++) printf(" "); for(j=i;j<i+4;j++) printf("*"); printf("\n");} getch();}
[此贴子已经被作者于2005-4-22 12:47:16编辑过]
第15楼的,修改如下:
#include<stdio.h> main() { int n,i,k=1; float answer=0; scanf("%d",&n); for(i=1;i<=n;i++) { answer+=k*(float)n/i ; k=-k; } printf("answer=%f",answer); getch(); }
#include <stdio.h>
float caculate ( float n , int count ) { float result = 0 ; int fuhao ; for ( int i = 1 ; i <= count ; i ++ ) { int flag = i ; if ( flag % 2 == 0 ) fuhao = -1 ; else fuhao = 1 ; result += fuhao * n / i ; } return result ; } int main () { float n ; int count ; scanf ( "%f%d" , &n,&count ) ; printf ("%f" , caculate (n ,count)) ; return 0 ; }