当前位置: 代码迷 >> C语言 >> 马上考试了,帮帮忙!!谢谢哥哥们!!
  详细解决方案

马上考试了,帮帮忙!!谢谢哥哥们!!

热度:114   发布时间:2005-01-14 08:55:00.0
马上考试了,帮帮忙!!谢谢哥哥们!!

1. 编写一程序,实现从键盘上输入的一字符串,将其中的小写字母变成大写,大写变成小写。

2.从键盘输入整数,统计正数和负数的个数,当输入为0时统计结束。

3.求1100之间的所有素数。

搜索更多相关的解决方案: 考试  

----------------解决方案--------------------------------------------------------
自己做吧,动一下脑筋,不然就不要学了!
----------------解决方案--------------------------------------------------------
1.

#include <stdio.h>
main(_){while((_=getch())!=10)putch(_>='a'&&_<='z'?_+'A'-'a':_>='A'&&_<='Z'?_-'A'+'a':_);}

2.
#include <stdio.h>
int a[2];
main(_)
{   for(;_;scanf("%d",&_),a[_>0]++,_==0&&printf(">0  :%d    <0  :%d\n",a[1],--a[0]));
}

or

#include <stdio.h>
main(_,a,b)
{   for(a=b=0;_;scanf("%d",&_),a+=_>0,b+=_<0,_==0&&printf(">0  :%d    <0  :%d",a,b));
}








----------------解决方案--------------------------------------------------------

上面的knocker 老兄,你的程序真是太经典了 不过人家初学,不要写的这么简短么,写长一点,让人家多学点么,呵呵 看我来写个长的; #include <stdio.h> #define DEBUG #define CHAR_NUM 50 typedef unsigned SIZE_T;

void *MEMSET(void *s, int c, SIZE_T n); void CONVERT(char *s);

void main(void) { FILE *fp; char ch[CHAR_NUM];

if((fp = fopen("out.txt", "w")) == 0) { #ifdef DEBUG printf("Can not open file!\n"); #endif return; } MEMSET(ch, 0, sizeof(ch)); printf("Please Input String:"); gets(ch); CONVERT(ch); #ifdef DEBUG printf("after convert the string is:%s\n", ch); #endif fprintf(fp, "%s", ch); fclose(fp); }

void *MEMSET(void *s, int c, SIZE_T n) { unsigned char *st = (unsigned char *)s; unsigned char ch = c;

while (n-- > 0) *st++ = ch; return s; }

void CONVERT(char *s) { while(*s) { if(*s >= 'A' && *s <= 'Z') { *s += 32; } else if(*s >= 'a' && *s <= 'z') { *s -= 32; } else ;

s++; } }


----------------解决方案--------------------------------------------------------

//我写了第一个小题的,不知道是否可以,请指教! //注:用VC通过编译的。 #include <stdio.h> #include <stdlib.h>

void main() { char *ch; int i; ch=(char*) malloc(sizeof(char)); printf("Please input:\n"); gets(ch); for(i=0;*ch!='\0';ch++,i++) { if(*ch>='a'&&*ch<='z'){ *ch=(char)(*ch-('a'-'A')); continue; } if(*ch>='A'&&*ch<='Z'){ *ch=(char)(*ch+('a'-'A')); } } ch=ch-i; printf("The converted string : \n"); printf("%s",ch); }


----------------解决方案--------------------------------------------------------
呵呵,都挺不错的!!
----------------解决方案--------------------------------------------------------
以下是引用young在2005-1-14 11:09:15的发言:

上面的knocker 老兄,你的程序真是太经典了 不过人家初学,不要写的这么简短么,写长一点,让人家多学点么,呵呵 看我来写个长的; #include <stdio.h> #define DEBUG #define CHAR_NUM 50 typedef unsigned SIZE_T;

void *MEMSET(void *s, int c, SIZE_T n); void CONVERT(char *s);

void main(void) { FILE *fp; char ch[CHAR_NUM];

if((fp = fopen("out.txt", "w")) == 0) { #ifdef DEBUG printf("Can not open file!\n"); #endif return; } MEMSET(ch, 0, sizeof(ch)); printf("Please Input String:"); gets(ch); CONVERT(ch); #ifdef DEBUG printf("after convert the string is:%s\n", ch); #endif fprintf(fp, "%s", ch); fclose(fp); }

void *MEMSET(void *s, int c, SIZE_T n) { unsigned char *st = (unsigned char *)s; unsigned char ch = c;

while (n-- > 0) *st++ = ch; return s; }

void CONVERT(char *s) { while(*s) { if(*s >= 'A' && *s <= 'Z') { *s += 32; } else if(*s >= 'a' && *s <= 'z') { *s -= 32; } else ;

s++; } }

确实不错,不过有点故意凋难的感觉……
----------------解决方案--------------------------------------------------------

  相关解决方案