
代码如下:
#include <stdioh>
int main(void)
{
printf("Hello, world!");
return 0;
}
一、首先,打开我们的Visual C++ 60软件,我使用的为中文版,软件主界面如下图所示:
1、然后点击上图工具栏中的文件,里面有个新建菜单,然后我们可以设置一下我们的工作空间,如下图所示:
2、然后在一步步默认点击确定,完成即可,此时工作空间就建立起来了。
二、接下来,再点击工具栏下的文件,里面有个新建菜单,点击它,出现下图的对话框:
1、点击确定即可,创建出一个helloworldc的小程序,然后我们就可以编写我们的Hello World小程序了。此时就需要我们的VC++ 60来编译此程序,编译无错误才运行此程序,编译按钮和运行按钮如下图的红色箭头处:
2、或者可以点击组建工具栏下的编译菜单项,然后再点击执行菜单项,也有快捷键,按Ctrl+F7编译此程序,按Ctrl+F5运行此程序。编译无错误的话,点击运行按钮后如下图所示:
扩展资料:
C语言的基本构成:
1、数据类型。C的数据类型包括:整型、字符型、实型或浮点型(单精度和双精度)、枚举类型、数组类型、结构体类型、共用体类型、指针类型和空类型。
2、常量与变量。常量其值不可改变,符号常量名通常用大写。变量是以某标识符为名字,其值可以改变的量。标识符是以字母或下划线开头的一串由字母、数字或下划线构成的序列,请注意第一个字符必须为字母或下划线,否则为不合法的变量名。变量在编译时为其分配相应存储单元。
3、数组。如果一个变量名后面跟着一个有数字的中括号,这个声明就是数组声明。字符串也是一种数组。它们以ASCII的NULL作为数组的结束。要特别注意的是,方括内的索引值是从0算起的。
程序就是读取文件到数组,再将数组进行排序,最后写入文件。
读写文件流程:fopen获取文件流(根据读写需求,选择参数,使用完必须调用fclose函数关闭),fscanf读取文件内容,fseek控制文件流指针,fprintf写入文件。
选择排序:每个循环周期选出一个最值,交换一次。
下面是代码(数组为动态数组):
#include <stdioh>
#include <malloch>
int maxLen;//数组长度
int read2Nums(char path[]);//读取
int write2File(int nums,char path[]);//写入
void showNums(int nums);
int px(int nums,int flag);//选择排序flag=1升序,flag=0降序
int main()
{
int nums=NULL;
char rPath[]="c:\\000dat",wPath[]="c:\\rankdat";
if(!(nums=read2Nums(rPath))) return 1;
showNums(nums);
printf("数组升序排列:\n");
if(px(nums,1)==-1) return 1;
showNums(nums);
printf("数组降序排列:\n");
if(px(nums,0)==-1) return 1;
showNums(nums);
printf("写入到文件路径%s下(存在覆盖,不存在新建)\n",wPath);
if(write2File(nums,wPath)==-1) return 1;
printf("写入成功!\n");
return 0;
}
void showNums(int nums)
{
int i;
if(nums) for(i=0,printf("文件内容:\n");i<maxLen;printf("%d ",nums[i]),i++);
printf("\n");
}
int px(int nums,int flag)
{
int i,j,n,temp;
if(!nums) return -1;
for(i=0;i<maxLen-1;i++)
{
n=i;
for(j=i+1;j<maxLen;j++)
{
if(flag && nums[n]>nums[j]) n=j;
if(!flag && nums[n]<nums[j]) n=j;
}
temp=nums[i],nums[i]=nums[n],nums[n]=temp;
}
return 1;
}
int write2File(int nums,char path[])
{
int i;
FILE fp=NULL;
if(!nums) return -1;
if(!(fp=fopen(path,"w"))) return -1;
//fseek(fp,SEEK_END);
for(i=0;i<maxLen;i++)
fprintf(fp,"%d ",nums[i]);
fclose(fp);
return 1;
}
int read2Nums(char path[])
{
int nums=NULL,temp=NULL,cnt=0;
FILE fp=NULL;
maxLen=10;
if(!(fp=fopen(path,"r"))) return NULL;
nums=(int )malloc(sizeof(int)maxLen);
if(!nums) return NULL;
while(fscanf(fp,"%d",&nums[cnt++])!=-1)
if(cnt==maxLen)//数组长度不够扩展(每次扩展10长度)
{
maxLen=maxLen+10;
temp=(int )realloc(nums,sizeof(int)maxLen);
if(temp) return NULL;
nums=temp;
}
if(--cnt<maxLen)//函数结束前,删除多余地址,减少内存占用
{
maxLen=cnt;
temp=(int )realloc(nums,sizeof(int)maxLen);
if(!temp) return NULL;
nums=temp;
}
fclose(fp);
return nums;
}
1
#include "stdioh"
#include "mathh"
#define Z 1e-20
int main()
{
float a,b;
printf("Please input A,B in Ax^2+B:\n");
scanf("%f%f",&a,&b);
if ((fabs(a)>Z && (ab<0))
printf("x=+/-%f\n",sqrt(-b/a));
else if ((fabs(a)>Z && (ab>0))
printf("x=+/-%fi\n",sqrt(b/a));
else if ((fabs(a)<=Z && (fabs(b)<=Z))
printf("x=any number\n");
else printf("no x!\n");
getchar();getchar();
return 0;
}
2
#include "stdioh"
int main()
{
int i;
float n[5],x;
printf("Please input 5 numbers:\n");
scanf("%f%f%f%f%f";n,n+1,n+2,n+3,n+4);
printf("+ number:");
for (i=0;i<5;i++)
if (n[i]>0) printf("%f,",n[i]);
x=n[0];
for (i=1;i<5;i++)
x=(x>n[i])x:n[i];
printf("\nThe max one is:%f\n",x);
getchar();getchar();
return 0;
}
函数指针~~我来写一个给你
#include "stdafxh"
int sum(int a, int b)
{
return a+b;
}
void swap(int a, int b)
{
int temp ;
temp = a;
a = b;
b = temp;
}
int (sumFunc)(int,int);
void (swapFunc)(int , int );
int _tmain(int argc, _TCHAR argv[])
{
int first = 0;
int second = 0;
printf("please input: ");
scanf("%d %d",&first,&second);
printf("%d, %d \n",first,second);
sumFunc = sum;
swapFunc = swap;
int total = sumFunc(first,second);
printf("sum: %d \n",total);
swap(&first,&second);
printf("%d, %d \n",first,second);
return 0;
}
已运行测试过。
c语言编译程序属于系统软件。
编译程序(Compiler,compilingprogram)也称为编译器,是指把用高级程序设计语言书写的源程序,翻译成等价的机器语言格式目标程序的翻译程序。
这里的编译程序是一种动作,是根据编译原理技术,由高级程序设计语言编译器翻译成机器语言二进制代码行为,因此它是系统软件。
扩展资料:
应用软件:是和系统软件相对应的,是用户可以使用的各种程序设计语言,以及用各种程序设计语言编制的应用程序的集合,分为应用软件包和用户程序。应用软件包是利用计算机解决某类问版题而设计的程序的集合,供多用户使用。比如浏览器、权百度云管家等等都是应用软件。
工具软件:是指在使用电脑进行工作和学习时经常使用的软件,比如电脑管家等杀毒软件,一般工具软件都属于应用软件。
上了大学有很多同学都在学习C语言,C++就是C语言的一种,那么怎么用c语言写一个简单的程序hello world呢,下边来给大家演示一下
工具/材料电脑,c语言软件
01鼠标左键双击c语言软件,打开,打开后界面如图,点击关闭即可
02点击上方程序窗口左上角的文件,选择新建
03在打开的窗口中选择文件,下边一般是第四个 c++Source file,输入文件名(hellwc),一定要以“c”为后缀结尾
04进入编辑页面在,页面编辑源代码就可以
#include<stdioh>
void main()
{
printf("hello world!"\n);
}
然后选择保存,打印,输出运行。
05输出的效果就是这样了,一个简单的c语言程序就写好了
特别提示所有的输入都要在英文半角的情况下输入,不然程序会不能识别,会报错。
#include<stdioh>
int main() {
int N = 0, n = 0;
printf("请输入被除数N\n");
scanf("%d", &N);
printf("请输入除数n\n");
scanf("%d", &n);
if (n == 0) {
printf("输入的除数为0,错误!本程序结束\n");
} else if (N % n == 0) {
printf("%d能被%d整除\n", N, n);
} else if (N % n != 0) {
printf("%d不能被%d整除,余数为%d\n", N, n, N % n);
}
return 0;
}
#include <stdioh>
#include <stdlibh>
/
主函数main中输入一组(10个)C语言成绩值到数组score[ ]中,
并输出如图所示的主菜单,根据不同的选择调用相应函数,编
写函数分别实现:
1- 输出平均值
2- 排序成绩
3- 输出比平均值低的成绩和个数
4- 输出及格率
5- 查找成绩
6- 添加成绩
0- 结束程序
/
//1、平均成绩函数
double AveScores(double [], double);
double AveScores(double score[], double count)
{
int i;
double sums = 0;
double average;
for(i = 0; i < count; i++)
{
sums += score[i];
}
average = sums / count;
return average;
}
//排序成绩函数由小到大
void SortScores(double [], int);
void SortScores(double score[], int count)
{
int i, j;
double temp;
for(i = 0; i < count; i++)
{
for(j = 0; j < count - i - 1; j++)
{
if(score[j] > score[j + 1])
{
temp = score[j + 1];
score[j + 1] = score[j];
score[j] = temp;
}
}
}
}
//输出比平均值低的成绩个数
double LowAve (double [], int, double);
double LowAve (double score[], int count, double average)
{
int i= 0;
double countlow = 0;
for(i = 0; i < count; i++)
{
if(score[i] < average)
{
countlow++;
}
}
return countlow;
}
//查找成绩
void FindScore(double [], int);
void FindScore(double score[], int count)
{
int i;
int index;
double input;
printf("请输入要查找的成绩");
scanf("%lf", &input);
for(i = 0; i < count; i++)
{
if(score[i] == input)
{
printf("找到了!此成绩在第%d个\n",i);
}
}
}
//添加成绩
int AddScore(double [], int);
int AddScore(double score[], int count)
{
int i = 0;
printf("请用户输入要添加的成绩:");
while(scanf("%lf", &score[i + count]) != 1 || &score[i + count] < 0)
{
fflush(stdin);
printf("请重新输入正数:");
}
count++;
return count;
}
int main()
{
int i, j;
int index; //数组元素下标
int choice; //用户选择
double average; //平均成绩
double temp; //临时变量
int count = 10; //成绩个数最多支持100个
double countlow; //低于平均成绩的个数
double score[100] = {76, 68, 98, 87, 71, 65, 49, 54, 80, 61};
double lowScore[100]; //用来存放低于平均成绩的数组
do
{
printf("\n");
printf("1、输出平均值\n");
printf("2、排序成绩\n");
printf("3、输出比平均值低的成绩和个数\n");
printf("4、输出及格率\n");
printf("5、查找成绩\n");
printf("6、添加成绩\n");
printf("0、结束程序\n");
printf("\n");
printf("请选择功能:");
while(scanf("%d", &choice) != 1 || choice < 0 || choice > 6)
{
fflush(stdin);
printf("请重新输入0-6的数字:");
}
switch(choice)
{
case 1://1- 输出平均值
average = AveScores(score,count);
printf("平均成绩为%2lf\n", average);
break;
case 2://2- 排序成绩
SortScores(score,count);
printf("排序后成绩为:\n");
for(i = 0; i < count; i++)
{
printf("第%d个成绩:\t",i + 1);
printf("%2lf\n",score[i]);
}
break;
case 3://3- 输出比平均值低的成绩和个数
for(i = 0; i < count; i++)
{
lowScore[i] = score[i];
}
SortScores(lowScore,count);
average = AveScores(score, count);
countlow = LowAve(lowScore,count,average);
printf("低于平均成绩的个数为%0lf\n", countlow);
for(i = 0; i < countlow; i++)
{
printf("第%d个低于平均的成绩:\t",i + 1);
printf("%2lf\n",lowScore[i]);
}
break;
case 4://4- 输出及格率
average = AveScores(score, count);
countlow = LowAve(score,count,average);
printf("及格率为:%2lf%%%\n",100 - countlow / count 100);
break;
case 5://5- 查找成绩
FindScore(score,count);
break;
case 6://6- 添加成绩
count = AddScore(score,count);
break;
}
}while(choice != 0);
return 0;
}
以上就是关于C语言编写程序全部的内容,包括:C语言编写程序、用C语言编写程序、用c语言编写程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)