フェアリーテイル56~ kadai1
C
#include <stdio.h>
#define NUMBER 5
#define FAILED -1
int search(int vc[], int key, int no){
    int i = 0;
    vc[no] = key;
    while(1){
        if(vc[i]==key){
            break;
        }
        i++;
    }
    return(i==no ? FAILED : i);
}

int main(void){
    int i,key,index;
    int vx[NUMBER+1];
    for (int i=0; i<NUMBER; i++) {
        printf("vx[%d]: ", i);
        scanf("%d", &vx[i]);
    }
    printf("探す値:");
    scanf("%d", &key);

    index = search(vx, key, NUMBER);
    
    if(index==FAILED){
        printf("探索失敗");
    }
    else {
        printf("%d is in %d\n", key, index);
    }
    return 0;
}
anonymous No title
C
#include <stdio.h>

int a[11] = {6, 7, 11, 12, 14, 18, 19, 21, 24, 28, 37};
int main(void){
    int key = 11;
    int l = -1;
    int r = sizeof(a)/sizeof(int);
    while (r-l > 1) {
        int m = l + (r - l)/2;
        if (a[m] > key) {
            r = m;
        }
        else {
            l = m;
        }
    }
    printf("%d", r);
    return 0;
}
フェアリーテイル56~ No title
C
#include <stdio.h>
#include <stdlib.h>
int main(void){
    unsigned char header[0x36];
    unsigned char color_parett[0x435-0x36];
    unsigned char **data;
    unsigned char *temp_data;
    char in_f_name[20] = "./LENNA.bmp", out_f_name[20] = "./output_copy.bmp";
    FILE *in_f, *out_f;
    long start_addr, end_addr;
    int width, height, color_bit;
    int i, j, k;
    if ((in_f=fopen(in_f_name, "rb"))==NULL){
        printf("Error on open file.\n");
    }

    /* header */
    for (int i=0; i<0x36; i++){
        header[i] = fgetc(in_f);
        // printf("%x: %x\n", i, header[i]);
    }
    start_addr = header[0x0A] + header[0x0B] * 0x100;
    end_addr = header[0x02] + header[0x03]*0x100 + header[0x04]*0x10000 + header[0x05]*0x1000000;
    width = header[0x12] + header[0x13] * 0x100;
    height = header[0x16] + header[0x17] * 0x100;
    color_bit = header[0x1C];
    printf("data_addr: 0x%x to 0x%x\n", start_addr, end_addr);
    printf("width: %d\n", width);
    printf("height: %d\n", height);
    printf("color: %xbit\n", color_bit);

    /* color parett*/
    for (int i=0x36; i<start_addr; i++){
        color_parett[i-0x36] = fgetc(in_f);
    }

    /* data */
    data = (char **)malloc(sizeof(char *) * height);
    for(i=0; i<height; i++){
        data[i] = (char *) malloc(sizeof(char)*width);
    }

    temp_data = (char *) malloc(sizeof(char)*height*width);

    // 1D data for 2D data
    temp_data = (char *)malloc(sizeof(char) * (end_addr - start_addr));
    for(i=start_addr; i<end_addr; i++){
        temp_data[i-start_addr] = fgetc(in_f);
    }
    /* convert to 2D data*/

    /*data output*/
    for (int i = 0; i < 0x36; i++)
    {
        printf("%x, ", header[i]);
    }
    for (int i = 0x36; i < start_addr; i++)
    {
        // printf("%x", color_parett[i]);
    }
    for (i = 0; i < end_addr - start_addr; i++)
    {
        // printf("%x", temp_data[i]);
    }

    /* writing */
    if ((out_f = fopen(out_f_name, "wb")) == NULL){
        printf("Error on open file.\n");
    }
    fprintf(out_f, "%c", 0x42);
    for (i = 1; i < 0x36; i++){
        fprintf(out_f, "%c", header[i]);
    }
    for (i = 0; i < 0x435-0x36; i++){
        fprintf(out_f, "%c", color_parett[i]);
    }
    for (i = 0; i < end_addr - start_addr; i++){
        fprintf(out_f, "%c", temp_data[i]);
    }
    fclose(out_f);

    free(temp_data);
    free(data);

}
anonymous No title
C
#include <stdio.h>
#include <stdlib.h>
#include<string.h>

 struct CELL{
    struct CELL *prev;
    int value;
    struct CELL *next;
};
struct CELL *insertCellPrev(struct CELL*, int);

struct CELL head;

struct CELL *appendCell(int data){
    struct CELL *p;
    int x=data;
    p=insertCellPrev(&head , x);
    return p;
}
struct CELL *insertCellPrev(struct CELL *p , int data){
    struct CELL *x;
    if(p==NULL){
        printf("insert : 引数が正しくありません\n");
        return NULL;
    }
    x=(struct CELL*)malloc(sizeof(struct CELL));
    if(x==NULL){
        printf("not enough memory\n");
        return NULL;
    }
    x->value=data;
    x->next=p;
    x->prev=p->prev;
    p->prev->next=x;
    p->prev=x;
    return x;
}

void printDlist(struct CELL *q){
    struct CELL *p;
    printf("LIST[");
    for(p=q; p!=&head ; p=p->next){
        printf(" %d ", p->value);
    }
    printf("]\n");

}
int deleteDuplicatedCell(int data){
    struct CELL *p;
    int num=0;
    for(p=head.next ; p!=&head ; p=p->next){
        if(p->value==data){
            num++;
            p->prev->next=p->next;
            p->next->prev=p->prev;
            free(p);
        }
    }
    if(num==0){
        return -1;
    }else{
        return num;
    }
}
void freeDlist(){
    struct CELL *p;
    int x=0;
    p=&head;
    for(p=head.next ; p->prev=&head ; p=p->next){
        printDlist(p);
        p->prev->next=p->next;
        p->next->prev=p->prev;
        free(p);
    }
}
void main(int argc , char *argv[]){
    struct CELL *p;
    int num;
    int n;
    head.prev = head.next = &head;

    for(int i=1 ; i<argc ; i++){
       p=appendCell(atoi(argv[i]));
    }
    printDlist(head.next);

while(1){
    printf("Delete Data : "); scanf("%d", &num);
    if(num<0){
        printf("free list\n");
        freeDlist();
        exit(0);
    }
    n=deleteDuplicatedCell(num);
    if(n!=-1){
        printf("Deleted : %d\n", n);
    }else if(n==-1){
        printf("Not deleted .....\n");
    }
    printDlist(head.next);
}

    return ;
}
anonymous No title
C
#include <stdio.h>

int main(void)
{
    printf("Hello World!");
    return 0;
}
anonymous No title
C
#include〈stdio.h〉
 int main(void)
 {
   int n;
      while(true){
         printf(“%d¥n”,n);
n = n + 1;
      }
     return 0;
  }
anonymous No title
C
#include〈stdio.h〉
 int main(void)
 {
   int n;
     for(n=0;n<10;n++){
         printf(“%d¥n”,n);
      }
     return 0;
  }
anonymous No title
C
#include〈stdio.h〉
int main(void)
{ 
  int x;
   printf("整数を入力して下さい");
   scanf("%d",&x);
  if (x % 2)
       puts("2で割り切れません");
  else 
       puts("2で割り切れます");
    return 0;
}
anonymous No title
C
#include〈stdio.h〉
int main(void)
{ 
  int x;
   printf("整数を入力して下さい");
   scanf("%d",&x);
  if (x%2)
       puts("2で割り切れません");
  else 
       puts("2で割り切れます");
    return 0;
}
anonymous No title
C
#include〈stdio.h〉
int main(void)
{
   printf("はじめまして。¥n”);
  return 0;
}
Don't you submit code?
Submit