1.编写一个程序,它由3个函数组成,每个函数分别保存在一个单独的源文件中。函数increment接受一个×××参数,它的返回值是该参数的值加1.increment函数应该位于文件increment.c中。第二个函数称为negate,它也接受一个×××参数,它的返回值是该参数的负值。最后一个函数是main,保存于文件main.c中,它分别用参数10,0,-10调用另外两个函数,并打印错误。

int increment(int n)
{
    return n+1;
}
int negate(int n)
{
    return -n;
}
int main()
{
    printf("%d\n", increment(10));
    printf("%d\n", increment(0));
    printf("%d\n", increment(-10));
    printf("%d\n", negate(10));
    printf("%d\n", negate(0));
    printf("%d\n", negate(-10));
    system("pause");
    return 0;
}

2.编写一个程序,它从标准输入读取c源代码,并验证所有的花括号都正确的成对出现。注意:不必担心注释内部、字符串常量内部和字符常量形式的花括号。

int main()
{
    int i = 0;
    char str[1000] = { 0 };
    int count = 0;
    printf("请输入:\n");
    scanf("%s", str);
    while (str[i] != '\n')
    {
       if (str[i] == '{')
       {
          count++;
       }
       if ((str[i] == '}')&&(count==0))
       {
          count--;
          break;
       }
       if ((str[i] == '}') && (count != 0))
       {
          count--;
       }
       i++;
    }
    if (count == 0)
    {
       printf("所有花括号成对出现\n");
    }
    else
    {
       printf("花括号未成对出现\n");
    }
    system("pause");
    return 0;
}