小練習:分段函式
分段函式要求實現的功能如下:
自變數取值:1, 2, 3, 4, 5, 6, 7, 8->值為8;
自變數取值:9, 10, 11, 12, 13, 14, 15, 16->值為16;
依次類推······
本程式在VS2017下執行通過#include<stdio.h> typedef int ElemType; ElemType Piecewisefun(ElemType item) { /* ElemType temp = item & ~0x0007; temp >>= 3; return(temp + 1)<<3; */ return(item + 8 - 1)&~7; } int main() { for (int i = 1; i < 200; ++i) { ElemType ret = Piecewisefun(i); printf("%4d",ret); if (i % 8 == 0) printf("\n"); } return 0; }
相關推薦
小練習:分段函式
分段函式要求實現的功能如下:自變數取值:1, 2, 3, 4, 5, 6, 7, 8->值為8;自變數取值:9, 10, 11, 12, 13, 14, 15, 16->值為
小練習:用socket實現Linux和Windows之間的通信
ren argc 漏洞 markdown tex sockets acc sas -m 在日常生活中,絕大部分人使用的機器通常是windows系統,可是對於研發人員,開發、編譯等工作往往是建立在linux機器上。其實。在服務器方面,Linux、UNIX和
python小練習:給定一個非空且為正整數的列表 按重復次數 降序排列輸出
class 數字 轉換成 原來 小練習 顯示 python index 去重 假設有個列表 a=[1,1,1,2,2,4,5,5,5,5] (非空且為正整數) 那麽根據要求 最終輸出的形式為 5,1,2,4 (按重復次數 降序排列輸出) 代碼實現及解釋: a=[1
辨析:分段函式是不是初等函式?
這是最近在上課的過程中作業題裡面遇到的一個問題。 關於初等函式,《高等數學》(同濟七版)中是這樣子定義的:由常數和基本初等函式經過有限次的四則運算和有限次的函式複合步驟所構成並可用一個式子表示的函式,稱為初等函式。 這個定義中,有兩個需要注意的:(1) 有限次;(2) 可用一個式子表
初夏小談:有關函式strstr(字串的查詢)
實現strstr 函式(字串的查詢) 實現strstr思想:是從源字串中依次尋找目標字串的首元素,再依次比較之後的字串,如果目標字串與所找位置都相同就返回,否則從源字串的下一個字元開始尋找,一次循壞。 #include<Aventador_SQ.h> int Strstr(ch
python小練習:讀入一個考試得分,判斷這個分數是哪個等級,並輸出,考慮異常場景
讀入一個考試得分,判斷這個分數是哪個等級,並輸出。 等級:》=90 優 ,>=80且小於90 良,》=70 且小於80,中,》=60且<70及格 《60 不及格 覆蓋場景: 考慮字元型別(str,float) 數字範圍(0-1
C語言:分段函式
題目: #include <math.h> int main() { double x,y; scanf("%lf",&x); if (x<0) y=0.5*(-x); else if (x<1
小練習:陣列元素的交換
/// 1.交換兩個陣列的元素,兩個陣列元素個數相同 #define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> int main() { int arr1[] = { 2, 3, 5, 4, 6, 7, 9, 12
小練習:Spring + SpringMVC + Mybatis 整合
注:將涉及的類(包、模組)交給Spring容器管理後,可在開發過程中注入需要的東西,通過Spring容器的管理,避免了各種類及其屬性的額外宣告使用,簡化開發流程 web.xml中,可以通過<context-param>批量把各種xml裡配置好的Bean一起載入到Spring容器中
小練習:mybatis + mapper.xml + xxxMapper.java (mapper代理)開發
stuMapper.xml: stuMapper.java: package xxx.testSpringMVC.myBatis.mapper; import xxx.testSpringMVC.myBatis.po.Stu; public interface stuMa
小練習:mybatis + Dao介面 + Dao 開發
文件結構: Dao介面 + Dao: package xxx.testSpringMVC.myBatis.Dao; import xxx.testSpringMVC.myBatis.po.Stu; import java.io.IOException; public inte
小練習:idea mybatis
文件結構: mapper中的stu.xml: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
C++小練習:輸出特殊圖形
1.輸出 #include<iostream> using namespace std; int main() { for (int row=1;row<=4;row++) { for (int k = 1;k<row;k++) {
opencv小練習:哈爾小波(Haar)
首先說一下一維haar小波的原理。 例如我們有一個一維的影象[2,4,6,8,10,12,14,16]. 求均值:我們求相鄰畫素的均值[3,7,11,15]。這個新的影象解析度就成了原來的一半(8/2=4)。 求差值。上面的均值我們儲存了影象的整體資訊。但
小練習:用socket實現Linux和Windows之間的通訊
在日常生活中,絕大部分人使用的機器一般是windows系統,但是對於研發人員,開發、編譯等工作往往是建立在linux機器上。事實上,在伺服器方面,Linux、UNIX和WindowsServer佔據了市場的大部分份額;在超級計算機方面,Linux取代Unix成為
爬蟲小練習:網頁原始碼隱藏資料(非ajax和js載入)之空氣質量網
注:一層一層剝開它的心,切記一次性訪問目標網頁from selenium import webdriver import requests import time option = webdriver
程式設計小練習:最大公約數,字串反序輸出,全排列,不用加減法求和,字串內容反序,字串中最長數字串,陣列是否遞增,陣列反轉,連結串列反轉,翻轉單詞順序
最大公約數 --- 遞迴、非遞迴 #include <stdio.h> int gcd(int a, int b); int gcd_recursive(int a, int b); int main(int argc, char *argv[]) {
Java語言中:++a與a++小練習 &與&&小練習 |與||小練習 boolean類型小練習
結果 pri 第一題 class 類型 ole true nbsp amp ---------------------------------------------------第一題int x = 1,y = 1; if(x++==2 & ++y==2) //f
day18 函式小練習,遞迴
1、寫一個函式,功能是告知 你所選定的小動物 的叫聲。 function animal(scream) { scream = String(window.prompt('input')); switch(scream){ case "dog" : console.log("汪")
mysql查詢的小練習例項:
mysql查詢的小練習例項: -- 1.查詢2014級有哪些班級(即班級中含有14字樣),要求去除重複的結果? select DISTINCT sclass from student where sclass like '%14%'; -- 正則表示式: sel