下列给定程序中,函数proc()的功能是:用递归算法计算斐波拉契级数列中第n项的值。从第一项起,斐波拉契级数序列为1,1,2,3,5,8,13,21,… 例如,若给n输入8,该项的斐波拉契级数值为21。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include<stdio.h> long proc(int g) { //****found**** switch(g); { case 0: return 0; //****found**** case 1; case 2: return 1; } return(proc(g-1)+proc(g-2)); } void main() { long fib; int n; printf("Input n:"); scanf("%d", &n); printf("n=%d\n", n); fib=proc(n); printf("fib=%d\n\n", fib); }
请补充函数proc(),该函数的功能是:分类统计一个字符串中元音字母和其他字符的个数(不区分大小写)。 例如,输入imnIaeouOWC,结果为:A:1 E:1 1:2 O:2U:1 other:4。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。 试题程序: #include<stdlib.h> #include<stdio.h> #include<conio.h> #define M 100 void proc(char *str,int bb[]) { char *p=str; int i=0; for(i=0; i<6; i++) ______; while(*p) { switch(*p) { case "A": case "a": bb[0]++; break; case "E": case "e": bb[1]++; break; case "I": case "i": bb[2]++; break; case "O": case "o": bb[3]++; break; case "U": case "u": bb[4]++; break; default: ______; } ______ } } void main() { char str[M],ss[6]="AEIOU"; int i; int bb[6]; system("CLS"); printf("Input a string:\n"); gets(str); printf("the string is:\n"); puts(str); proc(str, bb); for(i=0; i<5; i++) printf("\n%c: %d", ss[i], bb[i]); printf("\nother: %d", bb[i]); }