C/VC進数間の変換マトリクス転置単語カウント

6206 ワード

十進法=="バイナリ十進法="十六進法十六進法="十進法マトリクス転置単語カウントコードをコンパイラにコピーして直接実行できます
/*               */
#include <stdio.h>
#include <conio.h>

void printb(int x, int n);
void main()
{
  int x,n;
  puts("Input an integer: ");
  scanf("%d", &x);
  printf("You input a decimal is :%d
", x); puts("After change to binary is:
"); /* printb(x, sizeof(x)*8); */ n=sizeof(x)*8; while(n>0) { putchar( '0'+((unsigned)(x&(1<<(n-1)))>>(n-1)) ); n--; } puts("
\a\2a\1a\3a\4a\5a\6a"); getch(); } void printb(int x, int n) { if(n > 0) { putchar( \'0\'+((x&(1<<(n-1)))>>(n-1)) ); printb(x,n-1); } }
/*            */

#include "Stdio.h"

int main(void)
{
    int n, i=0,k;
    int t;
    char c;
    char hex[100]={0};
    char temp[100]={0};
    printf("Input interger number: ");
    scanf("%d", &n);
    while(n>0)
    {
       k=n%16;
       if(k>=0&&k<=9)
         c='0'+k;
         else if(k>=10)
            c='a'+(k-10);
        temp[i]=c;
        i++;
       n=n/16;
    }
    for(k=0;k<i/2;k++)
     {t=temp[k]; temp[k]=temp[i-k-1];temp[i-k-1]=t;}
    printf("%sH",temp);
    getch();
  return 0;
}
/*        */
/*          */
#include "Stdio.h"
#include "conio.h"
#include "string.h"
#include "math.h"
#define MAXSIZE 100

int htoi(char *s);
int main(void)
{
    /*            */
    
    char hex[MAXSIZE]={0};
    int n,i=0;
    char ch;
    printf("Input a hex(    ) number: ");
    while((ch=getchar())!=EOF && i<MAXSIZE)
    {	
        if(ch>='0'&&ch<='9'||ch>='a'&&ch<='f'||ch>='A'&&ch<='F')
    	{
            hex[i]=ch;
        	i++;
    	}
        else
    	{
            fflush(stdin);
            hex[i]='\0';
            printf("The hex %s to decimal is: %d
",hex, htoi(hex)); printf("Continue or quit?(Y/N)"); if((ch=getchar())=='N'|| ch=='n') { break; } i=0; fflush(stdin); } // fflush(stdin); // printf("Input a hex( ) number: "); } // getch(); return 0; } int htoi(char *s) { int len,i; int n=0; len = strlen(s); for(i=0;i<len&&s[i]!='\0';i++) { if(s[i]>='0'&&s[i]<='9') { n=n+((s[i]-'0')*pow(16,len-i-1)); } else if(s[i]>='a'&&s[i]<='f') { n=n+((10+(s[i]-'a'))*pow(16,len-i-1)); } else if(s[i]>='A'&&s[i]<='F') { n=n+((10+(s[i]-'A'))*pow(16,len-i-1)); } } return n; }

マトリックスてんいコード
/*        */
//      
#include "Stdio.h"
#define N 5

void printRect(int *a[]);
void convertRect(int *a[]);
int main(void)
{
    int rect[N][N];
    int i,j;
    srand((unsigned)time(NULL));
    for(i=0;i<N;i++)
      for(j=0;j<N;j++)
        {
          rect[i][j]=rand();
        }
    puts("Before convert:
"); printRect(rect); convertRect(rect); puts("After convert:
"); printRect(rect); getch(); return 0; } void printRect(int *a[]) { int i,j; for(i=0;i<N;i++) { for(j=0;j<N;j++) { printf("%10d",a[i][j]); } puts("
"); } } void convertRect(int *a[]) { int i,j; int t; for(i=0;i<N;i++) for(j=i+1;j<N;j++) { t =a[i][j]; a[i][j]=a[j][i]; a[j][i]=t; } }

 
/*6、            ,            (        ), "000"           ,  :
Twinkle twinkle little star 000(  )
twinkle  little  star
2      1     1    

*/ #include "stdio.h" /*#include "malloc.h"*/ #include "stdlib.h" #include <string.h> #define MAXSIZE 100 char *alpha[MAXSIZE] = {0}; // int num[MAXSIZE] = {0}; // void countAlpha(char *buf, int size); void main() { char dateBuf[200]; int len = 0; int k; printf("Please input a string and result with 000:
"); // dateBuf = malloc(200*sizeof(char)); // for char *dateBuf if (dateBuf == NULL) exit(1); // scanf("%s", dateBuf); gets(dateBuf); len = strlen(dateBuf); countAlpha(dateBuf, len); printf("
Alpha\tcount

"); // puts(dateBuf); // free(dateBuf); for (k = 0; num[k] != 0; k++) { printf("%s\t%d
", alpha[k], num[k]); } getch(); //free // for (k = 0; alpha[k] != NULL; k++) // { // if (alpha) // free(alpha[k]); // } } void countAlpha( char *buf, int size ) { // if(buf == NULL) return; int i = 0, j = 0; int flag; char temp[100] = {0}; while(i < size) { flag = 0; while (buf[i] == ' ' || buf[i] == '\t') { i++; flag = 1;} if (buf[i] >= 65 && buf[i] < 91) buf[i] += 32; if (!flag) { temp[j] = buf[i]; j++; i++; } else if (flag && j > 0) { int k = 0, flag2 = 0; if (strcmp(temp, "000") == 0) return; while(num[k] != 0) k++; alpha[k] = malloc(strlen(temp)); for (k = 0; num[k] != 0; k++) { if ( strcmp(temp, alpha[k]) == 0 ) { flag2 = 1; num[k]++; break; } } if (!flag2) { strcpy(alpha[k], temp); num[k] = 1; } j = 0; memset(temp, '\0', 100); } } }