iOS学习笔记--(c基础题9)

   // test1();//字符数组初始化
   // test2();//通过键盘录入为字符数组赋初值
   // test3();
  //test4();//统计单词的数量(不能判断没有单词的情况)
   // test5();//统计单词的另一种写法
   // test6();
    //test7();

// char a[]=”dsfsf”;
// printf(“%d\n”, Mystrlen(a));

//char a[100]=” dsf fsf “;
// Mystrtrim(a);//去掉给定字符串两边的空格(中间的不去除)
// Mystrltrim(a);//去掉左边的空格
// Mystrrtrim(a); //右边的空格
printf(“%d\n”,test10(3));//斐波那契

//
//  main.m
//  c91 test
//
//  Created by dq on 15/7/27.
//  Copyright (c) 2015年 dq. All rights reserved.
//

#import <Foundation/Foundation.h>
void test1()//字符数组初始化
{
    char a[]={'a','c','b','\0'};//初始化的两种方法   使用''录入的时候要加上'\0'结束符
    char a1[]="acb";
    printf("%s\n",a);//格式化输出的两种方法
    int i=0;
    while (a1[i]!='\0') {
        printf("%c",a1[i]);
        i++;
    }
}
void test2()//通过键盘录入为字符数组赋初值
{
    char a[100];
    char ch;
    int i=0;
    while ((ch = getchar())!='\n') {
        a[i]=ch;
        i++;
    }
   // a[i]='\0';
    printf("%s\n",a);//输出字符串的两种方式
    puts(a);
}
void test3()//大小写转换
{
    char a[]="sdfsFDFD";
    for (int i=0; i<strlen(a); i++) {
        if (islower(a[i])) {
            a[i]=toupper(a[i]);
        }
       else
       {
           a[i]=tolower(a[i]);
       }

    }
    printf("%s",a);
}
void test4()//统计单词个数
{
    char a[]="we are best";
    int i=0,count=0;
    while (a[i]!='\0') {
        if (a[i]==' ') {
            count++;
        }
        i++;
    }
    count++;
    printf("%d",count);
}
void test5()
{
     char a[]=" d dsf s fs ";
    int i=0;
    int flag=0;
    int count=0;
    while (a[i]!='\0') {
        if (a[i]==' ') {
            flag=0;
        }
        else if(flag==0)
        {
            count++;
            flag=1;
        }
        i++;
    }
    printf("%d",count);
}
void test6()
{
    int count = 0;
    for (int i=1; i<5; i++) {
        for (int j=1; j<5; j++) {
            for (int k=1; k<5; k++) {
                if (i!=j&&i!=k&&j!=k) {
                    printf("%d\n",i*100+j*10+k);
                    count ++;
                }
            }
        }
    }
    printf("%d",count);

}
void test7()
{
    long int x,y,i;
    for ( i=1; i<100000; i++) {
        x=sqrt(i+100);
        y=sqrt(i+268);
        if (x*x==(i+100)&&y*y==(i+268)) {
            printf("%ld\n",i);
        }

    }

}
int Mystrlen(char *p)
{
    int count=0;
    while (*p++!='\0') {
        count++;
    }
    return count;
}
void  Mystrtrim(char *p)
{
   // char *a=NULL;

 //   a = malloc(100*sizeof(char));
    int i=0;
    while (p[i]==' ') {

        i++;
    }
    int j=(int)strlen(p)-1;
    while (p[j]==' ') {

        j--;
    }
    for (int k=i ; k<=j; k++) {
        printf("%c",p[k]);
    }
    printf("\n");
}
void  Mystrrtrim(char *p)
{
    int i=0;
    while(p[i]==' ') {
        i++;
    }
    int j=(int)strlen(p)-1;

    for (int k=i ; k<=j; k++) {
        printf("%c",p[k]);
    }
      printf("\n");
}
void  Mystrltrim(char *p)
{
  //  char *a=NULL;
   // a = malloc(100*sizeof(char));
    int i=0;
    int j=(int)strlen(p)-1;
    while(p[j]==' ') {
        j--;
    }
    for (int k=i ; k<=j; k++) {
        printf("%c",p[k]);
    }
      printf("\n");
}
int test10(int n)
{
    if (n<3) {
        return 1;
    }
    else
        return test10(n-1)+test10(n-2);
}
int main(int argc, const char * argv[]) {
    @autoreleasepool {
       // test1();//字符数组初始化
       // test2();//通过键盘录入为字符数组赋初值
       // test3();
      //test4();//统计单词的数量(不能判断没有单词的情况)
       // test5();//统计单词的另一种写法
       // test6();
        //test7();
//        char a[]="dsfsf";
//        printf("%d\n", Mystrlen(a));

//char a[100]="  dsf  fsf  ";
//        Mystrtrim(a);//去掉给定字符串两边的空格(中间的不去除)
//        Mystrltrim(a);//去掉左边的空格
//        Mystrrtrim(a); //右边的空格
        printf("%d\n",test10(3));//斐波那契
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值