某单据1x4x7C语言编程,C语言入门必学——刚需帖子详情 - 网易云课堂

本文主要是介绍某单据1x4x7C语言编程,C语言入门必学——刚需帖子详情 - 网易云课堂,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

A164DD3D488647169E193BC86D0CEBB5.png?imageView&thumbnail=120y120&quality=100_49x49x1x95.png

置顶

精华

老师参与

计算元音个数:

/*

* 从终端输入若干的字符,对其中的元音字母进行统计

*/

#include 

#include 

#define BUFFER 128

int is_vowel(char);

int main(void)

{

char str[BUFFER];

printf("Input string: ");

scanf("%s", str);

int count = 0;

int len = strlen(str);

for (int i = 0; i 

if (!is_vowel(str[i]))

count++;

printf("The string have %d vowel words.\n", count);

return 0;

}

int is_vowel(char c)

{

static const char vowel[] = "aeiou";

int len = sizeof vowel;

for (int i = 0; i 

if (vowel[i] == c)

return 0;

}

return 1;

}

[lhf@localhost work]$ ./vowel

Input string: hello world

The string have 2 vowel words.

A164DD3D488647169E193BC86D0CEBB5.png?imageView&thumbnail=120y120&quality=100_49x49x1x95.png

置顶

精华

老师参与

1000以内的质数:

/*

* 求出1000以内的所有质数

*

*/

#include 

#define MAX 1000

int is_prime(int);

void print_prime(int *, int);

int main(void)

{

int p[MAX] = {2};

int count = 0;

for (int i = 3; i <= MAX; i += 2) {

if (!is_prime(i)) {

p[++count] = i;

}

}

print_prime(p, count);

return 0;

}

int is_prime(int n)

{

for (int i = 2; i * i <= n; i++) {

if (!(n % i))

return 1;

}

return 0;

}

void print_prime(int *p, int n)

{

for (int i = 0; i 

printf("%3d", p[i]);

printf("%c", (i + 1) % 10 ? ' ' : '\n');

}

printf("\n");

return;

}

[lhf@localhost work]$ ./prime

2   3   5   7  11  13  17  19  23  29

31  37  41  43  47  53  59  61  67  71

73  79  83  89  97 101 103 107 109 113

127 131 137 139 149 151 157 163 167 173

179 181 191 193 197 199 211 223 227 229

233 239 241 251 257 263 269 271 277 281

283 293 307 311 313 317 331 337 347 349

353 359 367 373 379 383 389 397 401 409

419 421 431 433 439 443 449 457 461 463

467 479 487 491 499 503 509 521 523 541

547 557 563 569 571 577 587 593 599 601

607 613 617 619 631 641 643 647 653 659

661 673 677 683 691 701 709 719 727 733

739 743 751 757 761 769 773 787 797 809

811 821 823 827 829 839 853 857 859 863

877 881 883 887 907 911 919 929 937 941

947 953 967 971 977 983 991

A164DD3D488647169E193BC86D0CEBB5.png?imageView&thumbnail=120y120&quality=100_49x49x1x95.png

置顶

精华

老师参与

水仙花数:

/*

* 求出1000以内的水仙花数:153 = 1^3 + 5^3 + 3^3

*

*/

#include 

#define MAX 1000

int main(void)

{

for (int i = 0; i <= MAX; i++) {

int sum = 0;

int narc = i;

int mod;

do {

mod = narc % 10;

sum += mod * mod * mod;

} while (narc /= 10);

if (sum == i)

printf("%d\n", i);

}

return 0;

}

[lhf@localhost work]$ ./narc

0

1

153

370

371

407

A164DD3D488647169E193BC86D0CEBB5.png?imageView&thumbnail=120y120&quality=100_49x49x1x95.png

置顶

精华

老师参与

字符串问题:

/*

* 在终端上实现如下输出:

* ABCDEF

* BCDEF

* CDEF

* DEF

* EF

* F

*

*/

#include 

int main(void)

{

const char str[] = "ABCDEF";

char *p;

for (p = str; *p != '\0'; p++)

puts(p);

return 0;

}

[lhf@localhost work]$ ./disappear

ABCDEF

BCDEF

CDEF

DEF

EF

F

A164DD3D488647169E193BC86D0CEBB5.png?imageView&thumbnail=120y120&quality=100_49x49x1x95.png

置顶

精华

老师参与

圆的面积问题:

/*

* 从半径为1开始,输出圆的面积,直到面积大于100为止。

*

*/

#include 

#include 

#define PI 3.14

#define MAX 100

int main(void)

{

double area = 0;

for (int i = 1; true; i++) {

area = PI * i * i;

if (area <= MAX)

printf("Radius of %2d, area of circle is %.2lf\n",

i, area);

else

break;

}

return 0;

}

[lhf@localhost work]$ ./circle

Radius of  1, area of circle is 3.14

Radius of  2, area of circle is 12.56

Radius of  3, area of circle is 28.26

Radius of  4, area of circle is 50.24

Radius of  5, area of circle is 78.50

A164DD3D488647169E193BC86D0CEBB5.png?imageView&thumbnail=120y120&quality=100_49x49x1x95.png

置顶

精华

老师参与

九九乘法表

/*

* 输出九九乘法表

*

*/

#include 

int main(void)

{

for (int i = 0; i 

for (int j = 0; j <= i; j++) {

printf("%dx%d = %-2d  ", j + 1, i + 1, (i + 1) * (j + 1));

}

printf("\n");

}

return 0;

}

[lhf@localhost work]$ ./9x9

1x1 = 1

1x2 = 2   2x2 = 4

1x3 = 3   2x3 = 6   3x3 = 9

1x4 = 4   2x4 = 8   3x4 = 12  4x4 = 16

1x5 = 5   2x5 = 10  3x5 = 15  4x5 = 20  5x5 = 25

1x6 = 6   2x6 = 12  3x6 = 18  4x6 = 24  5x6 = 30  6x6 = 36

1x7 = 7   2x7 = 14  3x7 = 21  4x7 = 28  5x7 = 35  6x7 = 42  7x7 = 49

1x8 = 8   2x8 = 16  3x8 = 24  4x8 = 32  5x8 = 40  6x8 = 48  7x8 = 56  8x8 = 64

1x9 = 9   2x9 = 18  3x9 = 27  4x9 = 36  5x9 = 45  6x9 = 54  7x9 = 63  8x9 = 72  9x9 = 81

A164DD3D488647169E193BC86D0CEBB5.png?imageView&thumbnail=120y120&quality=100_49x49x1x95.png

置顶

精华

老师参与

计算N个数的和:

/*

* 从终端输入N个数(以字母Q/q作为终止),求和。

*

*/

#include 

#include 

#define BUFFER 128

int main(void)

{

char line[BUFFER];

int sum = 0;

int num = 0;

printf("Input N number, without 'Q' or 'q', summarize.\n");

do {

printf("Input a number: ");

scanf("%s", line);

if (!strcmp(line, "Q") || !strcmp(line, "q"))

break;

sum += atoi(line);

} while (true);

printf("sum is %d\n", sum);

return 0;

}

[lhf@localhost work]$ ./sum

Input N number, without 'Q' or 'q', summarize.

Input a number: 2

Input a number: 4

Input a number: 43

Input a number: 23

Input a number: q

sum is 72

A164DD3D488647169E193BC86D0CEBB5.png?imageView&thumbnail=120y120&quality=100_49x49x1x95.png

置顶

精华

老师参与

计算奇数和偶数问题

/*

* 从终端输入数据,直到输入0值为止,计算出其中偶数的个数和平均值,以及

* 奇数的个数和平均值。

*/

#include 

#include 

int main(void)

{

int num;

int count_odd = 0, count_even = 0;

long sum_odd = 0, sum_even = 0;

float average_odd, average_even;

do {

printf("Input a Number(until 0): ");

scanf("%d", &num);

if (!num)

break;

else if (num % 2) {

count_odd++;

sum_odd += num;

} else {

count_even++;

sum_even += num;

}

} while (true);

average_odd = (double)sum_odd / count_odd;

average_even = (double)sum_even / count_even;

printf("%d numbers of odd, average is %.2f\n", count_odd, average_odd);

printf("%d numbers of even, average is %.2f\n", count_even, average_even);

return 0;

}

[lhf@localhost work]$ ./odd_even

Input a Number(until 0): 2

Input a Number(until 0): 4

Input a Number(until 0): 3

Input a Number(until 0): 5

Input a Number(until 0): 8

Input a Number(until 0): 9

Input a Number(until 0): 0

3 numbers of odd, average is 5.67

3 numbers of even, average is 4.67

A164DD3D488647169E193BC86D0CEBB5.png?imageView&thumbnail=120y120&quality=100_49x49x1x95.png

置顶

精华

老师参与

fibonacci 前40项

/*

* 写出fibonacci数列的前40项(不能用数组实现)

* 0, 1, 1, 2, 3, 5, 8, 13, 21...

*

*/

#include 

int main(void)

{

int fib = 0, fibo = 1;

int tmp;

for (int i = 0; i 

printf("%ld ", fib);

tmp = fibo;

fibo = fib + fibo;

fib = tmp;

if (!(i % 10))

putchar('\n');

}

putchar('\n');

return 0;

}

[lhf@localhost work]$ ./fibonacci

0

1 1 2 3 5 8 13 21 34 55

89 144 233 377 610 987 1597 2584 4181 6765

10946 17711 28657 46368 75025 121393 196418 317811 514229 832040

1346269 2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986

A164DD3D488647169E193BC86D0CEBB5.png?imageView&thumbnail=120y120&quality=100_49x49x1x95.png

置顶

精华

老师参与

银行利率问题:

/**

* A以每年10%的单利息投资了100美元,B以每年5%的复合利息投资了100美元,

* 编写一程序,计算需要多少年B的投资总额才会超过A,并且显示出各自的资产总额

*

*/

#include 

#define BASE_A 100

#define BASE_B 100

int main(void)

{

int year = 1;

double assets_a = BASE_A, assets_b = BASE_B;

while (assets_a >= assets_b) {

assets_a += BASE_A * 0.1;

assets_b += assets_b * 0.05;

year++;

}

printf("%d year late assets of A 

year, assets_a, assets_b);

return 0;

}

[lhf@localhost work]$ ./assets

28 year late assets of A 

A164DD3D488647169E193BC86D0CEBB5.png?imageView&thumbnail=120y120&quality=100_49x49x1x95.png

置顶

精华

老师参与

百钱买百鸡:

/*

* 百钱买百鸡:鸡翁一,值钱五;鸡母一,值钱三;三鸡雏,值钱一,百钱买百鸡,

* 问鸡翁,鸡母,鸡雏各几何?

*

*/

#include 

#define MONEY 100

#define MANY 100

int main(void)

{

int cock = 5;

int hen = 3;

int chick = 1;  // 0.333...

int max_cock = MONEY / cock;

int max_hen = MONEY / hen;

int max_chick = MONEY * 3;

int i = 0;

float money_cock;

float money_hey;

float money_chick;

int money = 0;

int count = 0;

for (int i = 0; i <= max_cock; i++) {

money_cock = cock * i;

for (int j = 0; j <= max_hen; j++) {

money_hey = hen * j;

for (int k = 0; k <= max_chick; k += 3) {

// because chick = 1

money_chick = chick * k / 3;

money = money_cock + money_hey + money_chick;

if ((money == MONEY) && (i + j + k == MONEY))

printf("[%d] cock: %-2d    hen: %-2d                                                    chick: %-2d\n", ++count, i, j, k);

}

}

}

return 0;

}

这篇关于某单据1x4x7C语言编程,C语言入门必学——刚需帖子详情 - 网易云课堂的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/336415

相关文章

python使用fastapi实现多语言国际化的操作指南

《python使用fastapi实现多语言国际化的操作指南》本文介绍了使用Python和FastAPI实现多语言国际化的操作指南,包括多语言架构技术栈、翻译管理、前端本地化、语言切换机制以及常见陷阱和... 目录多语言国际化实现指南项目多语言架构技术栈目录结构翻译工作流1. 翻译数据存储2. 翻译生成脚本

Go语言中三种容器类型的数据结构详解

《Go语言中三种容器类型的数据结构详解》在Go语言中,有三种主要的容器类型用于存储和操作集合数据:本文主要介绍三者的使用与区别,感兴趣的小伙伴可以跟随小编一起学习一下... 目录基本概念1. 数组(Array)2. 切片(Slice)3. 映射(Map)对比总结注意事项基本概念在 Go 语言中,有三种主要

C语言中自动与强制转换全解析

《C语言中自动与强制转换全解析》在编写C程序时,类型转换是确保数据正确性和一致性的关键环节,无论是隐式转换还是显式转换,都各有特点和应用场景,本文将详细探讨C语言中的类型转换机制,帮助您更好地理解并在... 目录类型转换的重要性自动类型转换(隐式转换)强制类型转换(显式转换)常见错误与注意事项总结与建议类型

Go语言利用泛型封装常见的Map操作

《Go语言利用泛型封装常见的Map操作》Go语言在1.18版本中引入了泛型,这是Go语言发展的一个重要里程碑,它极大地增强了语言的表达能力和灵活性,本文将通过泛型实现封装常见的Map操作,感... 目录什么是泛型泛型解决了什么问题Go泛型基于泛型的常见Map操作代码合集总结什么是泛型泛型是一种编程范式,允

C#多线程编程中导致死锁的常见陷阱和避免方法

《C#多线程编程中导致死锁的常见陷阱和避免方法》在C#多线程编程中,死锁(Deadlock)是一种常见的、令人头疼的错误,死锁通常发生在多个线程试图获取多个资源的锁时,导致相互等待对方释放资源,最终形... 目录引言1. 什么是死锁?死锁的典型条件:2. 导致死锁的常见原因2.1 锁的顺序问题错误示例:不同

Android kotlin语言实现删除文件的解决方案

《Androidkotlin语言实现删除文件的解决方案》:本文主要介绍Androidkotlin语言实现删除文件的解决方案,在项目开发过程中,尤其是需要跨平台协作的项目,那么删除用户指定的文件的... 目录一、前言二、适用环境三、模板内容1.权限申请2.Activity中的模板一、前言在项目开发过程中,尤

C语言小项目实战之通讯录功能

《C语言小项目实战之通讯录功能》:本文主要介绍如何设计和实现一个简单的通讯录管理系统,包括联系人信息的存储、增加、删除、查找、修改和排序等功能,文中通过代码介绍的非常详细,需要的朋友可以参考下... 目录功能介绍:添加联系人模块显示联系人模块删除联系人模块查找联系人模块修改联系人模块排序联系人模块源代码如下

PyCharm接入DeepSeek实现AI编程的操作流程

《PyCharm接入DeepSeek实现AI编程的操作流程》DeepSeek是一家专注于人工智能技术研发的公司,致力于开发高性能、低成本的AI模型,接下来,我们把DeepSeek接入到PyCharm中... 目录引言效果演示创建API key在PyCharm中下载Continue插件配置Continue引言

基于Go语言实现一个压测工具

《基于Go语言实现一个压测工具》这篇文章主要为大家详细介绍了基于Go语言实现一个简单的压测工具,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录整体架构通用数据处理模块Http请求响应数据处理Curl参数解析处理客户端模块Http客户端处理Grpc客户端处理Websocket客户端

使用SQL语言查询多个Excel表格的操作方法

《使用SQL语言查询多个Excel表格的操作方法》本文介绍了如何使用SQL语言查询多个Excel表格,通过将所有Excel表格放入一个.xlsx文件中,并使用pandas和pandasql库进行读取和... 目录如何用SQL语言查询多个Excel表格如何使用sql查询excel内容1. 简介2. 实现思路3