c語言文件編程題
在C語言中,「^」是雙目運算符,用於完成兩個數據的按位異或操作。該運算符可以用來進行兩個數據的比較或者對一個數據中的某些位進行處理。
1、if(a^0x8)a=0;//如果a不等於08H則a=0
2、a=a^0xf0;//將a的高4位取反低4位不變後存回a
㈡ C語言編程題
long fun(int k)
{
if(i<2)
return 1L;
return k*fun(k-1);
}
或:
#include "stdio.h"
main()
{
double h,c;
//printf("Input h ");
scanf("%lf",&h);
c=5.0/9*(h-32);
printf("c=%lf",c);
}

(2)c語言文件編程題擴展閱讀:
C語言包含的各種控制語句僅有9種,關鍵字也只有32 個,程序的編寫要求不嚴格且以小寫字母為主,對許多不必要的部分進行了精簡。實際上,語句構成與硬體有關聯的較少,且C語言本身不提供與硬體相關的輸入輸出、文件管理等功能,如需此類功能,需要通過配合編譯系統所支持的各類庫進行編程,故c語言擁有非常簡潔的編譯系統。
㈢ C語言的一道數據文件的編程題
void readBytes(FILE *fp,long int nOffset,int nCount) //a
{ int i;
  char c;
  fseek(fp,nOffset,SEEK_SET);
  for ( i=0;i<nCount;i++ ) { fread(&c,1,1,fp); printf("%c",c); }
  printf("\n");
}
void readBytes(FILE *fp,long int nOffset,int nCount,char *buffer) //b
{ fseek(fp,nOffset,SEEK_SET);
  fread(buffer,1,nCount,fp);
}
㈣ 關於C語言里文件的編程題!考試要用的!急用!多謝!
int=1;
使用while(1){getline逐行讀取數據;i++;如果該數據小於50則break}
使用while(1)循環, 讀取下一行,{如果大於上一個數據number,並且小於50,則RecordNumber=i;number=y,否則繼續讀取下一行比較}
最後輸出i就可以了
㈤ c語言編程題
用一個簡單的函數說吧。
main()
{
 
printf("你好!\n");
}
說明:    
l        
main是主函數的函數名,表示這是一個主函數。
l        
每一個C源程序都必須有,且只能有一個主函數(main函數)。
l        
函數調用語句,printf函數的功能是把要輸出的內容送到顯示器去顯示。
         
printf函數是一個由系統定義的標准函數,可在程序中直接調用。如果不是標准函數,就要用到預處理命令了,比如說如果你要求sin值,那麼要用到sin(),而這個不是標准函數,就要用預處理命令把含有該函數的函數文件加到程序裡面,sin()是數學函數,就在原來的第一行上面插入一行#include<math.h>
㈥ C語言文件編程題!!急!!!
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>void main()
{ 
 int *buf1,*buf2;
 int *num,i,j,k,tmp,filelen1,filelen2,numlen1,numlen2,numlen;
 FILE *fp1,*fp2,*fp3;
 if((fp1=fopen("f1.c","r"))==NULL)
 {
  printf("open f1 error!\n");
  exit(0); 
 }
 if((fp2=fopen("f2.c","r"))==NULL)
 {
  printf("open f2 error!\n");
  exit(0); 
 }
 if((fp3=fopen("f3.c","w"))==NULL)
 {
  printf("open f3 error!\n");
  exit(0); 
 }
 fseek(fp1, 0, SEEK_END);
 filelen1 = ftell(fp1);
 fseek(fp2, 0, SEEK_END);
 filelen2 = ftell(fp2); buf1=(int*)malloc(sizeof(int)*filelen1);
 buf2=(int*)malloc(sizeof(int)*filelen2);
 
 numlen1=0;
 numlen2=0;
 rewind(fp1); //指針移到文件開始
 rewind(fp2); //指針移到文件開始 i=0;
 while(!feof(fp1)) 
 {
  fscanf(fp1,"%d",&buf1[i++]);//讀取文件中的數字  
  numlen1++;
 }
 for(i=0;i<numlen1;i++) 
  printf("%d ",buf1[i]);
 printf("\n"); i=0;
 while(!feof(fp2)) 
 {
  fscanf(fp2,"%d",&buf2[i++]);//讀取文件中的數字  
  numlen2++;
 }
 for(i=0;i<numlen2;i++) 
  printf("%d ",buf2[i]);
 printf("\n"); numlen=numlen1+numlen2;
 num=(int*)malloc(sizeof(int)*(numlen));//num存儲所有數字
 
 for(i=0,j=0;i<numlen;i++)
 {
  if(i<numlen1)
   num[i]=buf1[i];//buf1中的數字存到num中
  else
   num[i]=buf2[j++];//buf2中的數字存到num中
 } for(i=0;i<numlen;i++) 
  printf("%d ",num[i]);
 printf("\n"); for(j=0;j<numlen-1;j++)
 {
  for(i=0;i<numlen-1-j;i++)
   if(num[i]<num[i+1]) //冒泡法排序
   {
    tmp=num[i];
    num[i]=num[i+1];
    num[i+1]=tmp;
   }
 }
 for(i=0;i<numlen;i++) 
  printf("%d ",num[i]);
 printf("\n"); for(i=0;i<numlen-1;i++) 
  for(j=i+1;j<numlen;)
  {
   if(num[i]==num[j])//存在相同的數字 就刪掉靠後的一個
   {
    for(k=j;k<numlen-1;k++)
     num[k]=num[k+1];
    numlen--;//刪掉一個數字之後就把num的長度減1
   } 
   else//有相同的數時j保持,否則加1
    j++;
  } for(i=0;i<numlen;i++) 
  printf("%d ",num[i]); 
 printf("\n"); for(i=0;i<numlen;i++)
 {
  fprintf(fp3,"%d ",num[i]);//每行寫入10個數字
  printf("%d ",num[i]);//每行寫入10個數字
  if((i+1)%10==0)
  {
   fprintf(fp3,"\n");//寫入換行符
   printf("\n");
  }
 }
 free(buf1);
 free(buf2);
 free(num);
 fclose(fp1);
 fclose(fp2);
 fclose(fp3); 
}
㈦ C語言,文件操作編程題,請教一下這個程序該怎麼寫

㈧ C語言結構體與文件編程題
VC++測試通過,,,,有問題到我空間留言~
#include<stdio.h>
#include<string.h>
struct Person
{
 char name[100];
 int  age;
 int  sex;
 char add[100];
 
};
int main(int argc, char* argv[])
{
 FILE *FIN;
 char STRING_COMMAND[30];
 if((FIN=fopen("c:/abc.txt","a+"))==NULL)
 {
  printf("不能打開該文件,或者找不到該文件~");
  return 0;
 }
 else
 {
  printf("請使用以下命令來完成操作:\n");
 }
 
 printf("-lsall            list all the person`s info!   \n");
 printf("-insert           insert one person`s info      \n");
 printf("-exit             exit the progronam            \n");
 printf("-lsname           list all the person`s name    \n");
 printf("-lsnameinfo[name] display the info of one person \n");
 while(1)
 {
  gets(STRING_COMMAND);
  if(strcmp(STRING_COMMAND,"-lsall")==0)
  { fseek(FIN,0,SEEK_SET);
  char in;
  in=getc(FIN);
  while(in!=EOF)
  {
   printf("%c",in);
   in=getc(FIN);
  }
  printf("Query successfully!\n");
  continue;
  }
  else if(strcmp(STRING_COMMAND,"-insert")==0)
  {
   struct Person newPerson;
   printf("name:");
   scanf("%s",&newPerson.name);
   printf("age:");
   scanf("%d",&newPerson.age);
   printf("sex:");
   scanf("%d",&newPerson.sex);
   printf("address:");
   scanf("%s",&newPerson.add);
   fseek(FIN,0,SEEK_END);
   fprintf(FIN,"name:%s\nage:%d\nsex:%d\naddress:%s\n",newPerson.name,newPerson.age,newPerson.sex,newPerson.add);
   printf("Insert successfully!\n");
   continue;
  }
  else if(strcmp(STRING_COMMAND,"-lsname")==0)
  {
   fseek(FIN,0,SEEK_SET);
   struct Person QueryName;
   while(feof(FIN)==0)
   {
    fscanf(FIN,"name:%s\n",&QueryName.name);
    fscanf(FIN,"age:%d\n",&QueryName.age);
    fscanf(FIN,"sex:%d\n",&QueryName.sex);
    fscanf(FIN,"add:%s\n",&QueryName.add);
    printf("%s\n",QueryName.name);
   }
   printf("Query successfully!");
  }
  else if(strcmp(STRING_COMMAND,"-lsnameinfo")==0)
  {   char ForCmp[20];
   gets(ForCmp);
   fseek(FIN,0,SEEK_SET);
   struct Person QueryName;
   while(feof(FIN)==0)
   {
    fscanf(FIN,"name:%s\n",&QueryName.name);
    fscanf(FIN,"age:%d\n",&QueryName.age);
    fscanf(FIN,"sex:%d\n",&QueryName.sex);
    fscanf(FIN,"add:%s\n",&QueryName.add);
    if(strcmp(QueryName.name,ForCmp)==0)
    {
    printf("name:%s\n",QueryName.name);
    printf("age:%d\n",QueryName.age);
    printf("sex:%d\n",QueryName.sex);
    printf("address:%s\n",QueryName.add);
    }
   }
   printf("Query successfully!");
  }
  else if(strcmp(STRING_COMMAND,"-exit")==0||strcmp(STRING_COMMAND,"-end")==0)
  {
   break;
  }
  else
  {
   printf("Bad command!\n");
  }
 }
 fclose(FIN);
 return 0;
}
㈨ 求教一個C語言關於文件的編程題
把file1.txt 放在編譯好的exe文件所在文件夾。代碼如下:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#defineMAXWORDS100
//qsort用到的字元串比較函數,用來比較單詞
intcompare(constvoid*pa,constvoid*pb)
{
returnstrcmp((char*)pa,(char*)pb);
}
intmain()
{
FILE*fp1=NULL,*fp2=NULL;
fp1=fopen("file1.txt","r");
fp2=fopen("file2.txt","wt");
if(!fp1||!fp2){
printf("Erroropenfile! ");
exit(-1);
}
charWords[MAXWORDS][64]={NULL};
charstr[64];
inti,cnt=0;//cnt保存了實際讀入的單詞個數,最多為MAXWORDS個
printf("file1content: ");
for(i=0;!feof(fp1)&&i<MAXWORDS;i++)
{
fscanf(fp1,"%s",str);
strcpy(Words[i],str);
Words[i][strlen(str)]='
