C语言消除逗号,PS:malloc基本用法
来源:互联网 发布:stata软件下载 编辑:程序博客网 时间:2024/04/27 17:11
//动态数组实现
//功能描述:动态数组的创建与使用
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
void main(){
int *array =0,num,i;
printf("please input the number of element:");
scanf("%d",&num);
//申请动态数组使用的内存块
array=(int *)malloc(sizeof(int)*num);
if(array==0){//内存申请失败
printf("out of memory,press any key to quit.....\n");
exit(0);//终止程序返回操作系统
}
//提示输入num个数据
printf("please input %d elements",num);
for(i=0;i<num;i++){
scanf("%d",&array[i]);
}
//输出刚才的num个数据
printf("%d elements are:\n",num);
for(i=0;i<num;i++){
printf("%d,",array[i]);
}
//去除最后一个数字后面的逗号
printf("\b \n");
free("array");//释放由malloc申请的内存块
}
//功能描述:动态数组的创建与使用
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
void main(){
int *array =0,num,i;
printf("please input the number of element:");
scanf("%d",&num);
//申请动态数组使用的内存块
array=(int *)malloc(sizeof(int)*num);
if(array==0){//内存申请失败
printf("out of memory,press any key to quit.....\n");
exit(0);//终止程序返回操作系统
}
//提示输入num个数据
printf("please input %d elements",num);
for(i=0;i<num;i++){
scanf("%d",&array[i]);
}
//输出刚才的num个数据
printf("%d elements are:\n",num);
for(i=0;i<num;i++){
printf("%d,",array[i]);
}
//去除最后一个数字后面的逗号
printf("\b \n");
free("array");//释放由malloc申请的内存块
}
0 0
- C语言消除逗号,PS:malloc基本用法
- C语言malloc用法
- C语言malloc用法
- C语言逗号运算符用法
- C语言中 malloc函数用法
- C语言中 malloc函数用法
- C语言中 malloc函数用法
- C语言中 malloc函数用法
- C语言中 malloc函数用法
- C语言逗号表达式
- c语言中的逗号
- C语言中的逗号
- c语言逗号表达式
- C语言逗号表达式
- C语言-------逗号表达式
- C语言-逗号表达式
- C语言逗号表达式
- C语言逗号表达式
- 黑马程序员之java基础学习
- 个人的专业知识库
- Radar Installation
- 几种任务调度的 Java 实现方法与比较
- JavaScript 自定义对象 for in
- C语言消除逗号,PS:malloc基本用法
- 汇编中函数返回结构体的方法
- 在本地配置tomcat
- ZOJ3492 Kagome Kagome
- Singleton
- 读 《think in java》 有感 -- 第(七)章
- nyist14年3月月赛题解
- 301重定向循环研究
- PullToRefreshListView实现根据拖拉的方向进行在顶部或者底部加载数据。