用Visual Studio2017写出第一个C程序

**

用Visual Studio2017写出第一个C程序

**
我是第一次写博客,希望大家多多指正。
如果你想用VS写C程序,你就必须安装下面那个使用C++的桌面开发:这个页面来自“工具”->"获取工具和功能"
安装这个工具之后,才能进行C语言的编辑。

打开VS,点击左上角“文件”->“新建”->“项目”在这里插入图片描述
打开“已安装”,找到“VS C++”,点击右边的“空项目”,下面有所创建的项目名称和位置,点击“确定”。
接下来,会在右边出现“解决方案资源管理器”,下面有你创建的项目,我创建了“C1”,在C1下有“源文件”,右击会出现“添加”,点击“添加”会出现“新建项”在这里插入图片描述
之后将会出现下面的页面,点击“C++文件(.cpp)”,下方会出现名称,将“.cpp”的后缀名改为“.c”,".cpp"是C++的后缀名在这里插入图片描述
接下来写代码在这里插入图片描述
点击“项目”,在最后会找到此项目属性,我的是“C1属性”在这里插入图片描述
接下来会出现“C1属性页面”,点击“C/C++”,右面会出现“SDL检查”,右边会出现一个乡下的箭头,选择“否”,点击右下角“应用”在这里插入图片描述
再此页面点击左边“链接器”,点击“系统”,右边第一行会出现“子系统”,点击右边箭头,选择“控制台(/SUBSYSTEM:CONSOLE)”,点击右下角“应用”,点击“确定”

在这里插入图片描述

返回编写代码页面,直接点击“本地Windows调试器”,代码正确就会直接出现运行结果在这里插入图片描述
这样第一个C语言代码就编写完成了。谢谢大家!!!

  • 32
    点赞
  • 73
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
好的,下面是一个简单的排课程序代码实现,你可以在Visual Studio中创建一个新的C++控制台项目,将代码复制粘贴进去,然后编译运行。 ```cpp #include <iostream> #include <string> #include <vector> #include <algorithm> #include <fstream> #include <sstream> using namespace std; struct Course { string name; int credits; vector<int> conflicts; // 与之冲突的课程编号 }; vector<Course> courses; // 所有课程 vector<vector<int>> schedule; // 课程表 bool has_conflict(int course_num, int time_slot) { // 判断某个课程在某个时间是否与已安排的课程冲突 for (int i = 0; i < schedule[time_slot].size(); i++) { int other_course_num = schedule[time_slot][i]; if (find(courses[course_num].conflicts.begin(), courses[course_num].conflicts.end(), other_course_num) != courses[course_num].conflicts.end()) { return true; } } return false; } int get_credit(int time_slot) { // 统计某个时间段的总学分数 int credit = 0; for (int i = 0; i < schedule[time_slot].size(); i++) { int course_num = schedule[time_slot][i]; credit += courses[course_num].credits; } return credit; } void print_schedule() { // 打印课程表 cout << "Course Schedule:" << endl; for (int i = 0; i < schedule.size(); i++) { cout << "Time Slot " << i + 1 << ": "; if (schedule[i].size() == 0) { cout << "No class scheduled" << endl; } else { for (int j = 0; j < schedule[i].size(); j++) { int course_num = schedule[i][j]; cout << courses[course_num].name << " "; } cout << "(" << get_credit(i) << " credits)" << endl; } } } int main() { // 读入课程信息 ifstream infile("courses.txt"); string line; while (getline(infile, line)) { Course course; istringstream iss(line); iss >> course.name >> course.credits; int conflict_num; while (iss >> conflict_num) { course.conflicts.push_back(conflict_num); } courses.push_back(course); } // 初始化课程表 int num_time_slots; cout << "Enter the number of time slots: "; cin >> num_time_slots; for (int i = 0; i < num_time_slots; i++) { vector<int> time_slot; schedule.push_back(time_slot); } // 排课 for (int i = 0; i < courses.size(); i++) { bool scheduled = false; for (int j = 0; j < num_time_slots && !scheduled; j++) { if (!has_conflict(i, j) && get_credit(j) + courses[i].credits <= 24) { schedule[j].push_back(i); scheduled = true; } } if (!scheduled) { cout << "Error: Could not schedule " << courses[i].name << endl; } } // 打印课程表 print_schedule(); return 0; } ``` 这个程序读入一个文件 `courses.txt`,文件格式如下: ``` Course1 3 2 3 4 Course2 4 1 3 Course3 2 1 2 Course4 3 2 4 ``` 其中每一行表示一门课程,第一个字段是课程名称,第二个字段是学分数,后面的字段是与之冲突的课程编号。程序会根据课程信息和时间段的数量,自动排出一个课程表并打印出来。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值