当前位置: 代码迷 >> C语言 >> [求助]有大侠能帮我答几道题吗?---之五
  详细解决方案

[求助]有大侠能帮我答几道题吗?---之五

热度:112   发布时间:2007-03-19 12:50:22.0
我周三考试,没时间自己钻研了,拜托各位指教指教了~
----------------解决方案--------------------------------------------------------
........................你们这门课 是什么时间开的?

----------------解决方案--------------------------------------------------------
要是学校 的普及考试 过60分 不难
----------------解决方案--------------------------------------------------------
一共就这八道题,大一时开的,我两次笔试没过了,这回上机考,直接关系到拿毕业证了,所以上来求救了!
----------------解决方案--------------------------------------------------------

掌握 循环( for() ,do() while ,while() ) 条件(if() , switch())
输出( printf() )输入( scanf() )的一般使用方法就查不多了
有可能会碰到#include<string.h>下那strlen() strcopy() strcat() strcmp()


函数名: strcat
功 能: 字符串拼接函数
用 法: char *strcat(char *destin, char *source);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char destination[25];
char *blank = " ", *c = "C++", *Borland = "Borland";
strcpy(destination, Borland);
strcat(destination, blank);
strcat(destination, c);
printf("%s\n", destination);
return 0;
}

函数名: stpcpy
功 能: 拷贝一个字符串到另一个
用 法: char *stpcpy(char *destin, char *source);
程序例:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
stpcpy(string, str1);
printf("%s\n", string);
return 0;
}

函数名: strcmp
功 能: 串比较
用 法: int strcmp(char *str1, char *str2);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
int ptr;
ptr = strcmp(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");
else
printf("buffer 2 is less than buffer 1\n");
ptr = strcmp(buf2, buf3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 3\n");
else
printf("buffer 2 is less than buffer 3\n");
return 0;
}

函数名: strcpy
功 能: 串拷贝
用 法: char *strcpy(char *str1, char *str2);
程序例:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
strcpy(string, str1);
printf("%s\n", string);
return 0;
}





----------------解决方案--------------------------------------------------------
在运行框里1+2+….+100的和,怎么输入啊?
----------------解决方案--------------------------------------------------------

如果LZ还有课本 ......课本上都有比较具体的介绍


----------------解决方案--------------------------------------------------------
呵呵,有是有,估么挖地三尺能找到!
----------------解决方案--------------------------------------------------------
应该学会应用数学方法,尽量避免循环
printf("%ld",(long)n*(n+1)>>1);
----------------解决方案--------------------------------------------------------
#include<stdio.h>
void main(){
int sum=0,i;
for(i=1;i<=100;i++){
sum=sum+i;
}
printf("1到100的和为:%d",sum);
}
----------------解决方案--------------------------------------------------------
  相关解决方案