C语言初学者四个程序,C语言初学者需要练习的几个程序,老司机深有体会

本文展示了多个C语言程序示例,包括两数之积、之商的计算,学生分数的等级评定,比较两个数的大小以及使用switch语句和循环结构。这些例子涵盖了基本的算术运算、条件控制语句(if-else)以及流程控制(switch,while,for)。
摘要由CSDN通过智能技术生成

#include/两数之积

#include

int main()

{

int a, b, s;

printf_s("请输入两个是整数");

scanf_s("%d%d", &a, &b);

s = a * b;

printf_s("两个整数之积是%d\n", s);

system("pause");

return 0;

}*/

#include

#include

int main()

{

int a, b, s;

printf_s("请输入两个是整数");

scanf_s("%d%d", &a, &b);

s = a / b;

printf_s("两个整数之商是%d\n", s);

system("pause");

return 0;

}

学生分数评比级别生成if else语句

#include

#include

void main()

{

int f = 0;//输入分数

char k = '\0';//分数层次

printf_s("请输入学生分数");

scanf_s("%d", &f);

if (f >=60 &&f<70)

{

k ='D';

}

else if (f>=70&&f<80)

{

k ='C';

}

else if (f >= 80 && f < 90)

{

k ='B';

}

else if (f >= 90 && f < 100)

{

k ='A';

}

else

{

k = 'w';

}

printf_s("学生等级为:%c\n", k);

system("pause");

}*/

/*

比较输入的两个数大小值// 每一个else语句都和前面最近的if对应,且每个if都对应else语句

#include

#include

void main()

{

int a, b;

printf_s("请输入两个数");

scanf_s("%d", &a);

scanf_s("%d", &b);

if (a != b)

{

if (a > b)

{

printf_s("a是较大的数 a=%d b=%d\n", a, b);

}

else

{

printf_s("b是较大的数 a=%d b=%d\n", a, b);

}

}

else

{

printf_s("a等于b且%d\n", a);

}

system("pause");

}*/

/*

switch语句运用 程序为输入变量转移到相应的位置并打印出来

#include

#include

void main()

{

int n;

printf_s("请输入第几季度");

scanf_s("%d",&n);

switch (n)

{

case 1:

printf_s("您输入的是第一季度\n");

break;//跳出本次循环

case 2:

printf_s("您输入的是第二季度\n");

break;

case 3:

printf_s("您输入的是第三季度\n");

break;

case 4:

printf_s("您输入的是第四季度\n", n);

break;

default://跳出整个循环

printf_s("您输入的季度有误\n");

}

system("pause");//打印屏幕

}

//while 语句运用 计算9到99的累加和

while 语句先判断在执行

#include

#include

int main()

{//花括号包含循环体

int i = 9;

int sum = 0;

while (i<=99)

{

sum = sum + i;//sum++//sum+=1;

i++;//i+=1//i=i+1;

}

printf_s("sum:%d\n",sum);

system("pause");

}

#include //fot语句计算循环 9到99累加

#include

int main()

{

int i,sum=0;

for (i = 9;i <= 99;i++)

{

sum = sum + i;

}

printf_s("%d\n", sum);

system("pause");

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值