将 1~100 的数据以 10x10 格式顺序输出
#include<stdio.h>int main()
{
int i, j, count=0;
for(i=1;i<=10;i++){
for(j=1;j<=10;j++){
count++; 我想问一下这个count在这块是什么意思,以及有什么作用
printf("%4d",count);
}
printf("\n");
}
return 0;
}
#include<stdio.h> int main() { int i, j, count=0; for(i=1;i<=10;i++){ //外层循环10次 for(j=1;j<=10;j++){ //内层循环10次 总共循环100次 count++; // count从0开始 每循环一次+1 printf("%4d",count); //以4宽度 输出 1~100 } printf("\n"); //每循环10次打印一次换行 } return 0; }
#include <stdio.h> typedef unsigned char uint8_t; typedef signed char int8_t; #define OPCODE_JMP 0xE9 //D7D6 D5D4 D3D2D1 D0 //11 10 100 1 #define TST_MSB(_op) (int8_t)((_op & 0x0f) << 4) #define TST_LSB(_op) (_op & 0x01) #define TST_RE(_op) (int8_t)(_op << 2) #define TST_FS(_op) (int8_t)(_op) int main(int argc, char *argv[]) { int i = 0, count = 0, re = 0; char s[] = "%0d"; if(TST_MSB(OPCODE_JMP) < 0) count += 100; if(TST_MSB(OPCODE_JMP << 1) < 0) count += 10; if(TST_MSB(OPCODE_JMP << 2) < 0) count += 1; if(TST_RE(OPCODE_JMP) < 0) re += 10; if(TST_RE(OPCODE_JMP << 1) < 0) re += 1; if(TST_FS(OPCODE_JMP) < 0) s[1] += 4; if(TST_FS(OPCODE_JMP << 1) < 0) s[1] += 2; for(i = TST_LSB(OPCODE_JMP) - 1; i < count; i++) { if(i % re == 0) printf("\n"); printf(s, i + 1); } return 0; }
#include <stdio.h> typedef unsigned char uint8_t; typedef signed char int8_t; #define OPCODE_JMP 0xE9 //FS RE COUNT HEAD //D7D6 D5D4 D3D2D1 D0 //11 10 100 1 uint8_t dmap[] = { 1, 10, 6, 100, '%', '0', 'd' }; #define _B2D(_b) dmap[_b - 1] #define HEAD(_op) (uint8_t)(_op & 0x01) #define COUNT(_op) _B2D(((_op & 0x0f) >> 1)) #define RE(_op) _B2D(((_op & 0x30) >> 4)) #define FS(_op) _B2D(((_op & 0xc0) >> 6)) + 0x30 #define MAKEWORD(_h, _l) (_h << 8 | _l) #define MAKEDWORD(_H, _L) (_H << 16 | _L) int parse_cmd(uint8_t c) { int pvs; pvs = MAKEDWORD(MAKEWORD(FS(c), RE(c)), MAKEWORD(COUNT(c), (HEAD(c) - 1))); return pvs; } int main(int argc, char *argv[]) { int i, pvs; pvs = parse_cmd(OPCODE_JMP); #define CASTU8(_int) ((uint8_t *)&_int) enum PVS { HD = 0, CNT, RE, FS }; for(dmap[5] = CASTU8(pvs)[FS], i = CASTU8(pvs)[HD]; i < CASTU8(pvs)[CNT]; i++) { if(0 == i % CASTU8(pvs)[RE]) printf("\n"); printf((char *)&dmap[4], i + 1); } return 0; }
#include <stdio.h> typedef unsigned char uint8_t; typedef signed char int8_t; #define OPCODE_JMP 0xE9 //define usr protocol bit //FS RE COUNT HEAD //D7D6 D5D4 D3D2D1 D0 //11 10 100 1 enum PVS { PHD = 0, CNT, REV, FST, STR }; uint8_t dmap[][8] = { #define UN_USED 255 {0, 1, UN_USED, UN_USED, UN_USED, UN_USED, UN_USED, UN_USED}, {0, 1, 10, 11, 100, 101, 110, 111}, {10, 10, 10, 11, UN_USED, UN_USED, UN_USED, UN_USED}, {0, 2, 4, 6, UN_USED, UN_USED, UN_USED, UN_USED}, {'%', '0', 'd', 0, UN_USED, UN_USED, UN_USED, UN_USED} }; #define _B2D(_r, _b) dmap[_r][_b] #define PHD(_op) _B2D(PHD, (uint8_t)(_op & 0x01)) //0/1 #define CNT(_op) _B2D(CNT, ((_op & 0x0f) >> 1)) //000-111 #define REV(_op) _B2D(REV, ((_op & 0x30) >> 4)) //00-11 #define FST(_op) _B2D(FST, ((_op & 0xc0) >> 6)) + 0x30 //00-11 #define MAKEWORD(_h, _l) (_h << 8 | _l) #define MAKEDWORD(_H, _L) (_H << 16 | _L) int parse_cmd(uint8_t c) { int pvs, i; pvs = MAKEDWORD(MAKEWORD(FST(c), REV(c)), MAKEWORD(CNT(c), (PHD(c)))); #define CASTU8(_int) ((uint8_t *)&_int) for(dmap[STR][1] = CASTU8(pvs)[FST], i = CASTU8(pvs)[PHD]; i <= CASTU8(pvs)[CNT]; i++) { printf(CASTU8(dmap[STR]), i); if(0 == i % CASTU8(pvs)[REV]) printf("\n"); } return pvs; } int main(int argc, char *argv[]) { int pvs, i; uint8_t *p; double pi = 3.1415926; //test pi for(p = (uint8_t *)&pi, i = 0; i < sizeof(double); i++) { printf("[%d:]0x%x\n", i + 1, p[i]); parse_cmd(p[i]); } //end of OPCODE_JMP parse_cmd(OPCODE_JMP); return 0; }
[此贴子已经被作者于2021-9-1 22:46编辑过]