当前位置: 首页 > 编程日记 > 正文

C语言程序设计50例(一)(经典收藏)

【程序1】
题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
1.程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去
      掉不满足条件的排列。

 1 #include "stdio.h"
 2 #include "conio.h"
 3 main()
 4 {
 5   int i,j,k;
 6   printf("\n");
 7   for(i=1;i<5;i++) /*以下为三重循环*/
 8     for(j=1;j<5;j++)
 9       for (k=1;k<5;k++)
10       {
11         if (i!=k&&i!=j&&j!=k) /*确保i、j、k三位互不相同*/
12         printf("%d,%d,%d\n",i,j,k);
13       }
14   getch();
15 }

【程序2】
题目:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高
   于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提
   成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于
   40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于
   100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数?
1.程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。

 1 #include "stdio.h"
 2 #include "conio.h"
 3 main()
 4 {
 5   long int i;
 6   int bonus1,bonus2,bonus4,bonus6,bonus10,bonus;
 7   scanf("%ld",&i); 
 8   bonus1=100000*0. 1;
 9   bonus2=bonus1+100000*0.75;
10   bonus4=bonus2+200000*0.5;
11   bonus6=bonus4+200000*0.3;
12   bonus10=bonus6+400000*0.15;
13   if(i<=100000)
14     bonus=i*0.1;
15     else if(i<=200000)
16       bonus=bonus1+(i-100000)*0.075;
17         else if(i<=400000)
18           bonus=bonus2+(i-200000)*0.05;
19             else if(i<=600000)
20               bonus=bonus4+(i-400000)*0.03;
21                 else if(i<=1000000)
22                   bonus=bonus6+(i-600000)*0.015;
23                     else
24                       bonus=bonus10+(i-1000000)*0.01;
25   printf("bonus=%d",bonus);
26   getch(); 
27 }

【程序3】
题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
1.程序分析:在10万以内判断,先将该数加上100后再开方,再将该数加上268后再开方,如果开方后
      的结果满足如下条件,即是结果。请看具体分析:

 1 #include "math.h"
 2 #include "stdio.h"
 3 #include "conio.h"
 4 main()
 5 {
 6   long int i,x,y,z;
 7   for (i=1;i<100000;i++)
 8   {
 9     x=sqrt(i+100); /*x为加上100后开方后的结果*/
10     y=sqrt(i+268); /*y为再加上168后开方后的结果*/
11     if(x*x==i+100&&y*y==i+268) /*如果一个数的平方根的平方等于该数,这说明此数是完全平方数*/
12     printf("\n%ld\n",i);
13   }
14   getch();
15 }

【程序4】
题目:输入某年某月某日,判断这一天是这一年的第几天?
1.程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊
      情况,闰年且输入月份大于3时需考虑多加一天。

 1 #include "stdio.h"
 2 #include "conio.h"
 3 main()
 4 {
 5   int day,month,year,sum,leap;
 6   printf("\nplease input year,month,day\n");
 7   scanf("%d,%d,%d",&year,&month,&day);
 8   switch(month) /*先计算某月以前月份的总天数*/
 9   {
10     case 1:sum=0;break;
11     case 2:sum=31;break;
12     case 3:sum=59;break;
13     case 4:sum=90;break;
14     case 5:sum=120;break;
15     case 6:sum=151;break;
16     case 7:sum=181;break;
17     case 8:sum=212;break;
18     case 9:sum=243;break;
19     case 10:sum=273;break;
20     case 11:sum=304;break;
21     case 12:sum=334;break;
22     default:printf("data error");break;
23   }
24   sum=sum+day; /*再加上某天的天数*/
25   if(year%400==0||(year%4==0&&year%100!=0)) /*判断是不是闰年*/
26     leap=1;
27   else
28     leap=0;
29   if(leap==1&&month>2) /*如果是闰年且月份大于2,总天数应该加一天*/
30     sum++;
31   printf("It is the %dth day.",sum);
32   getch(); 
33 }

【程序5】
题目:输入三个整数x,y,z,请把这三个数由小到大输出。
1.程序分析:我们想办法把最小的数放到x上,先将x与y进行比较,如果x>y则将x与y的值进行交换,
      然后再用x与z进行比较,如果x>z则将x与z的值进行交换,这样能使x最小。

 1 #include "stdio.h"
 2 #include "conio.h"
 3 main()
 4 {
 5   int x,y,z,t;
 6   scanf("%d%d%d",&x,&y,&z);
 7   if (x>y)
 8     {t=x;x=y;y=t;} /*交换x,y的值*/
 9   if(x>z)
10     {t=z;z=x;x=t;} /*交换x,z的值*/
11   if(y>z)
12     {t=y;y=z;z=t;} /*交换z,y的值*/
13   printf("small to big: %d %d %d\n",x,y,z);
14   getch(); 
15 }

【程序6】
题目:用*号输出字母C的图案。
1.程序分析:可先用'*'号在纸上写出字母C,再分行输出。

 1 #include "stdio.h"
 2 #include "conio.h"
 3 main()
 4 {
 5   printf("Hello C-world!\n");
 6   printf(" ****\n");
 7   printf(" *\n");
 8   printf(" * \n");
 9   printf(" ****\n");
10   getch(); 
11 }

【程序7】
题目:输出特殊图案,请在c环境中运行,看一看,Very Beautiful!
1.程序分析:字符共有256个。不同字符,图形不一样。

 1 #include "stdio.h"
 2 #include "conio.h"
 3 main()
 4 {
 5   char a=176,b=219;
 6   printf("%c%c%c%c%c\n",b,a,a,a,b);
 7   printf("%c%c%c%c%c\n",a,b,a,b,a);
 8   printf("%c%c%c%c%c\n",a,a,b,a,a);
 9   printf("%c%c%c%c%c\n",a,b,a,b,a);
10   printf("%c%c%c%c%c\n",b,a,a,a,b);
11   getch(); 
12 }

【程序8】
题目:输出9*9口诀。
1.程序分析:分行与列考虑,共9行9列,i控制行,j控制列。

 1 #include "stdio.h"
 2 #include "conio.h"
 3 main()
 4 {
 5   int i,j,result;
 6   printf("\n");
 7   for (i=1;i<10;i++)
 8   {
 9     for(j=1;j<10;j++)
10     {
11       result=i*j;
12       printf("%d*%d=%-3d",i,j,result); /*-3d表示左对齐,占3位*/
13     }
14     printf("\n"); /*每一行后换行*/
15   }
16   getch();
17 }

【程序9】
题目:要求输出国际象棋棋盘。
1.程序分析:用i控制行,j来控制列,根据i+j的和的变化来控制输出黑方格,还是白方格。

 1 #include "stdio.h"
 2 #include "conio.h"
 3 main()
 4 {
 5   int i,j;
 6   for(i=0;i<8;i++)
 7   {
 8     for(j=0;j<8;j++)
 9       if((i+j)%2==0)
10         printf("%c%c",219,219);
11       else
12         printf("  ");
13     printf("\n");
14   }
15   getch(); 
16 }

【程序10】
题目:打印楼梯,同时在楼梯上方打印两个笑脸。 
1.程序分析:用i控制行,j来控制列,j根据i的变化来控制输出黑方格的个数。

 1 #include "stdio.h"
 2 #include "conio.h"
 3 main()
 4 {
 5   int i,j;
 6   printf("\1\1\n"); /*输出两个笑脸*/
 7   for(i=1;i<11;i++)
 8   {
 9     for(j=1;j<=i;j++)
10       printf("%c%c",219,219);
11     printf("\n");
12   }
13   getch(); 
14 }

 

转载于:https://www.cnblogs.com/iloverain/p/5523582.html

相关文章:

python多线程执行类中的静态方法

在python 中如果通过多线程的方式执行某个方法很简单&#xff0c;只需要把同步函数的第一个参数为该函数对象即可。但是如果函数对象是某个类的静态方法&#xff0c;这时候如果直接使用类的该函数对象会报错。此时需要构造一个代理的方法来实现。 如&#xff1a;上一个博文中的…

检测缓存文件是否超时

(BOOL)isTimeOutWithFile:(NSString *)filePath timeOut:(double)timeOut {//获取文件的属性NSDictionary *fileDict [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];//获取文件的上次的修改时间NSDate *lastModfyDate fileDict.fileModificat…

JavaScript创建对象–如何在JS中定义对象

Objects are the main unit of encapsulation in Object-Oriented Programming. In this article, I will describe several ways to build objects in JavaScript. They are:对象是面向对象编程中封装的主要单元。 在本文中&#xff0c;我将介绍几种使用JavaScript构建对象的方…

MyBatis中#{}和${}的区别

------------------------siwuxie095 MyBatis 中 #{} 和 ${} 的区别 1、在 MyBatis 的映射配置文件中&#xff0c;动态传递参数有两种方式&#xff1a; &#xff08;1&#xff09;#{} 占位符 &#xff08;2&#xff09;${} 拼接符 2、#{} 和 ${} 的区别 &#xff08;1&#xff…

十进制字符串转十六进制字符串

NSString *colorStr[self.model.sclass_color substringFromIndex:1]; unsigned long cor strtoul([colorStr UTF8String],0,16);

gi克隆github文件_如何构建GitHub文件搜索功能的克隆

gi克隆github文件In this article, we will build a project that mimics the lesser known but awesome file search functionality provided by GitHub.在本文中&#xff0c;我们将构建一个项目&#xff0c;该项目模仿GitHub提供的鲜为人知但功能强大的文件搜索功能。 To se…

ipython --pandas

d定义: pandas是一个强大的Python数据分析的工具包。 pandas是基于NumPy构建的。 安装方法: pip install pandas import pandas as pd pandas的主要功能 具备对其功能的数据结构DataFrame、Series 集成时间序列功能 提供丰富的数学运算和操作 灵活处理缺失数据 Series 定义:Ser…

玩转Android之二维码生成与识别

二维码&#xff0c;我们也称作QRCode&#xff0c;QR表示quick response即快速响应&#xff0c;在很多App中我们都能见到二维码的身影&#xff0c;最常见的莫过于微信了。那么今天我们就来看看怎么样在我们自己的App中集成二维码的扫描与生成功能。OK&#xff0c;废话不多说&…

属性字符串(富文本)的使用

改变字符串中某些字符串字体的颜色 NSMutableAttributedString *attrStr[[NSMutableAttributedString alloc] initWithString:str]; [attrStr addAttribute:NSForegroundColorAttributeName value:kUIColorFromRGB(0xb2151c) range:[str rangeOfString:[NSString stringWith…

如何使用create-react-app在本地设置HTTPS

Running HTTPS in development is helpful when you need to consume an API that is also serving requests via HTTPS. 当您需要使用同时通过HTTPS服务请求的API时&#xff0c;在开发中运行HTTPS会很有帮助。 In this article, we will be setting up HTTPS in development …

Swift强制解析

IDE:Xcode Version7.3.1 Swift中"数据类型?"表示这是可选类型&#xff0c;即 某个常量或者变量可能是一个类型&#xff0c;也可能什么都没有&#xff0c;不确定它是否有值&#xff0c;也许会是nil。 比如&#xff1a; let num1 “123” let num2 Int(number1) pri…

rfc6455 WebSockets

https://tools.ietf.org/html/rfc6455 转载于:https://www.cnblogs.com/cheungxiongwei/p/8385719.html

2020-mb面试指南_2020年最佳代码面试准备平台

2020-mb面试指南Software developer interviews are rapidly evolving. Years ago, mastering data structures and common algorithms was enough to ace an interview and get a job. Today though, employers want candidates with real-world experience and skills. 软件开…

设计模式学习笔记(一)之工厂模式、单例模式

一、工厂模式 (1)简单工厂模式&#xff1a; 1 public interface IProduct { 2 3 public void saleProduct(); 4 5 } 创建一个产品接口&#xff0c;有一个卖产品的方法。 1 public class ProductA implements IProduct{ 2 3 public void saleProduct(){ 4 Sy…

iOS使用支付宝支付步骤

开发平台 (http://open.alipay.com/index.htm(这个里面找不到sdk) 需要进入下面的链接&#xff09; 使用支付宝进行一个完整的支付功能&#xff0c;大致有以下步骤&#xff1a; 1>先与支付宝签约&#xff0c;获得商户ID&#xff08;partner&#xff09;和账号ID&#xff08…

heroku_了解如何使用Heroku部署全栈Web应用程序

herokuBuilding a full stack web app is no mean feat. Learning to deploy one to production so that you can share it with the world can add an additional layer of complexity.构建全栈式Web应用程序绝非易事。 学习将其部署到生产环境中&#xff0c;以便您可以与世界…

SpringMVC学习手册(三)------EL和JSTL(上)

1.含义 EL: Expression Language , 表达式语言JSTL: Java Server Pages Standard Tag Library, JSP标准标签库 2.测试项目构建 2.1 复制JSTL的标准实现 复制Tomcat中webapps\examples\WEB-INF\lib下的两个jar包到新建项目目录的WEB-INF\lib下2.2 在JSP文件中使用tagli…

OpenStack Heat模板详解

Heat模板全称为heat orchestration template&#xff0c;简称为HOT。 1 典型Heat模板结构 heat_template_version: 2015-04-30 description:# a description of the template parameter_groups:# a declaration of input parameter groups and order parameters:# declaration …

如何从头开始构建自己的Linux Dotfiles Manager

As a new linux &#x1f427; user, you might realize that there are a bunch of configuration files present in your system. These special files are called "dotfiles". 作为新的Linux用户&#xff0c;您可能会意识到系统中存在大量配置文件。 这些特殊文件…

D3.js、HTML5、canvas 开发专题

https://www.smartdraw.com/genogram/ http://www.mamicode.com/info-detail-1163777.html D3折线图 https://www.cnblogs.com/hwaggLee/p/5073885.html js-d3画图插件 http://www.xiaomlove.com/2014/06/29/d3-js简单画图-箭头连接随机圆圈/ 连线 http://www.decemberc…

单向链表JAVA代码

//单向链表类publicclassLinkList{ //结点类 publicclassNode{ publicObject data; publicNode next; publicNode(Object obj,Node next){ this.data obj; this.next next; } } Node head; //记录…

forkjoin rxjs_如何通过吃披萨来理解RxJS运算符:zip,forkJoin和Combine

forkjoin rxjs什么是RxJS&#xff1f; (What is RxJS?) Reactive programming is an asynchronous programming paradigm concerned with data streams and the propagation of change - Wikipedia响应式编程是一种与数据流和变更传播有关的异步编程范式 -Wikipedia RxJS is a…

SQLserver数据库操作帮助类SqlHelper

1 SqlHelper源码 using System; using System.Data; using System.Xml; using System.Data.SqlClient; using System.Collections; namespace SQL.Access {/// <summary>/// SqlServer数据访问帮助类/// </summary>public sealed class SqlHelper{#region 私有构造…

python框架之Flask基础篇(一)

一.第一个hello world程序 # codingutf-8 from flask import Flaskapp Flask(__name__)app.route(/) def hello_world():return Hello World!if __name__ __main__:app.run(debugTrue) 1.app参数的设置&#xff1a; 以下几种方式全部拿debug模式举例&#xff1a; .方式一&…

flask部署机器学习_如何开发端到端机器学习项目并使用Flask将其部署到Heroku

flask部署机器学习Theres one question I always get asked regarding Data Science:关于数据科学&#xff0c;我经常被问到一个问题&#xff1a; What is the best way to master Data Science? What will get me hired?掌握数据科学的最佳方法是什么&#xff1f; 什么会雇…

UVALive2678:Subsequence

UVALive2678:Subsequence 题目大意 给定一个数组A和一个整数S。求数组A中&#xff0c;连续且之和不小于S的连续子序列长度最小值。 要求复杂度:Ο(n) Solution 用变量L表示所选区间最左端下标&#xff0c;用变量R表示所选区间最右端下标&#xff0c;用变量sum表示所选区间的和。…

【BZOJ-3712】Fiolki LCA + 倍增 (idea题)

3712: [PA2014]Fiolki Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 303 Solved: 67[Submit][Status][Discuss]Description 化学家吉丽想要配置一种神奇的药水来拯救世界。吉丽有n种不同的液体物质&#xff0c;和n个药瓶&#xff08;均从1到n编号&#xff09;。初始时&am…

访问系统相册或调用摄像头

头文件&#xff1a;#import <MobileCoreServices/MobileCoreServices.h> 协议&#xff1a;<UINavigationControllerDelegate, UIImagePickerControllerDelegate> // 调用系统相册获取图片 - (IBAction)getImageFromAlbum:(id)sender {// 判断系统相册是否可用&…

unity镜像_通过镜像学习Unity Multiplayer Basics

unity镜像Unity is one of the most well-known and established engines for game development, and Mirror is a third-party, open source networking solution that allows you to add multiplayer to your games.Unity是最著名的游戏开发引擎之一&#xff0c;而Mirror是第…

java内存模型和线程安全

转载于:https://www.cnblogs.com/Michael2397/p/8397451.html