Chinaunix首页 | 论坛 | 博客
  • 博客访问: 111073
  • 博文数量: 26
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 344
  • 用 户 组: 普通用户
  • 注册时间: 2013-07-21 23:11
文章分类
文章存档

2014年(23)

2013年(3)

分类: C/C++

2014-04-08 10:30:05

#include
#define M 20
/*
一维数组的倒置
数组a刚被调用时,调用的是数组的第一个数据,*a是可以直接代替数组a的,调用*a和调用数组a没多大的区别
*/
void fun(int *x,int n)
{
    int *p,m=n/2,*i,*j;
    i=x;
    j=x+n-1;
    p=x+m;
    for(;i     {
        int t=*i;
        *i=*j;
        *j=t;
    }
}
void main()
{
    int i,a[M],n;
    printf("Enter n:\n");
    scanf("%d",&n);
    printf("The original array:\n");
    for(i=0;i         scanf("%d",a+i);   //  a+i 就是数组a[i]
    fun(a,i);    //数组名a代表该数组首地址, 与&a[0]作用相同,*a即a[0]
    printf("\nThe array inverted:\n");
    for(i=0;i         printf("%d  ",*(a+i));
}
/* 一维数一维数组应用组应用 */
#include "stdio.h"
#include "stdlib.h"
void main()
{
    int  Employee[10]={27000,32000,32500,27500,30000,29000,31000,32500,30000,26000};
    int  Index;
    int  NewSalary;
    int  Selection;
    while(1)
    {
        printf("===================================================\n");
        printf("=Simple Employee Salary Management System         =\n");
        printf("=1.Display employee salary                        =\n");
        printf("=2.Modify employee salary                         =\n");
        printf("=3.Quit                                           =\n");
        printf("Please input your choose:");
        scanf("%d",&Selection);
        if(Selection==1||Selection==2)
        {
            printf("**Please input the employee number:");
            scanf("%d",&Index);
            if(Index<10)
            {
                 printf("**Employee Number is %d.",Index);
                 printf("The Salary is %d\n",Employee[Index]);
            }
            else
            {
                    printf("##The error employee number!\n");
                    exit(1);  // 需要stdlib.h头文件,表示异常退出.这个1是返回给操作系统的
            }
        }
        switch(Selection)
        {
            case  1:
                break;
             case   2:
                printf("**Please input new salary:");
                scanf("%d",&NewSalary);
                Employee[Index]=NewSalary;
                break;
             case    3:
                exit(1);
                break;
        }
        printf("\n");
   }
}
阅读(1310) | 评论(0) | 转发(0) |
0

上一篇:双缓存绘图浅谈

下一篇: java获取日历

给主人留下些什么吧!~~