Join date : 01/01/1970
| Tiêu đề: code 15 mới các chú bác vào mà chém gió (chém chuẩn vào nhớ) Wed Jul 08, 2009 4:23 pm | |
| - Code:
-
#include<stdio.h> #include<conio.h> #include<string.h>
/* void input(int *n,char s[][100]); void least(int n, char s[][100]); void substring(int n, char s[][100]);
void main() { int n; char s[20][100]; clrscr(); input(&n,s); least(n,s); substring(n,s); getch();
} void input(int *n,char s[][100]) { int i; do{ printf("\nInput N= "); scanf("%d",n ); }while(*n<=0||*n>=10); for(i=0;i<*n;i++) { printf("\nInput string [%d]= ",i); fflush(stdin); gets(s[i]); } } void least(int n,char s[][100]) { int i,min; min=strlen(s[0]); for(i=0;i<n;i++) { if(min>strlen(s[i])) min=strlen(s[i]); } printf("\nThe strings have least length in the strings:\n"); for(i=0;i<n;i++) { if(min==strlen(s[i])) puts(s[i]); } }
void substring(int n,char s[][100]) { int i; for(i=0;i<n;i++) { strstr(s[i],s[0]); } printf("\nThe strings have sub-string is the first string in the N strings:\n"); for(i=0;i<n;i++) { if(strstr(s[i],s[0])) puts(s[i]); } } */
#include<stdlib.h> #include<math.h> void input(int *n); void fibo(int n,long int a[]); void out(int n,long int a[]); int ktscf(int a); void square(int n,long int a[]); void menu(void);
void main() { int n,b; long int a[25]; char ch; do{ clrscr(); menu(); printf("\nChoice: "); ch=getchar(); switch(ch) { case '1': input(&n); getch(); break; case '2': fibo(n,a); out(n,a); getch(); break; case '3': fibo(n+5,a); printf("\nso thu %d= %ld",n+5,a[n+4]); getch(); break; case '4': square(n,a); getch(); break; case '5': exit(0); } }while(ch!='5');
}
void input(int *n) { do{ printf("\ninput N= "); scanf("%d",n); }while(*n<=0||*n>=20); }
void fibo(int n,long int a[]) { int i; a[0]=a[1]=1;
for(i=2;i<n;i++) { a[i]=a[i-1]+a[i-2] ;
} }
void out(int n,long int a[]) { int i; for(i=0;i<n;i++) { printf("%ld\t",a[i]); } } void square(int n,long int a[]) { int i; printf("\nAll number in the array fibonacci has N elements that is square number\n"); printf("%d\t",1); for(i=2;i<n;i++) { if(ktscf(a[i])==1) printf("%d\t",a[i]); } } int ktscf(int a) { if(pow(sqrt(a),2)==a) return 1; return 0; } void menu(void) { printf("\n1. Input N (0<N<20)"); printf("\n2. Print the array of N first Fibonacci numbers"); printf("\n3. Caculate the value of item [N+5]"); printf("\n4. Display all numbers in the array Fibonacci has N elements that is square number."); printf("\n5. Exit"); }
| |
|