C+C C×C
1.C语言中,long被存储为四个字节的补码。写一个程序,分别将这四个字节的内容取出,以16进制的方式显示在屏幕上。程序所需的long由用户从键盘输入,0表示输入结束。
程序运行效果如下:
input n: 12345678<回车>
hex: 00 BC 61 4E
input
n: -12345678<回车>
hex: FF 43 9E B2
input n: 0<回车>
bye!
#include<stdio.h>
int main()
{
long n,i,x;
printf("input n:");
scanf("%d",&n);
if(n==0)
printf("bye!\n");
else
{
printf("hex:");
for(i=0;i<8;i++)
{
if(i!=0&&i%2==0)
printf(" ");
x=((n&(0xf<<(28-4*i)))>>(28-4*i))&(0xf);
printf("%X",x);
}
printf("\n");
}
return 0;
}
2.有一行用户输入的英文句子 (长度<80,无标点,单词之间可能有多个空格)
。写一个程序,计算出句子中出现的所有单词以及单词出现的次数。要求所有找到的单词和次数都预先存储在下面这个数组中:struct tagWord
{ char word[20]; int count;} wordCount[40]; 最后再统一输出。
例如用户输入:abc ab ab abc abcd
输出为:
abc: 2
ab: 2
abcd: 1
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,k,u,t=0,h=0;
char c;
struct tagWord
{
char word[20];
int count;
}wordCount[40];
for(i=0;i<40;i++)
{
for(j=0;j<20;j++)
{
wordCount[i].word[j]=0;
wordCount[i].count=0;
}
}
for(i=0,j=0,k=0;i<80;i++,h=0)
{
c=getchar();
if(c!=' '&&c!='\n')
{
t=0;
wordCount[j].word[k]=c;
k++;
}
else
{
if(c==' '&&t==0)
{
for(u=0;u<j;u++)
{
if(strcmp(wordCount[u].word,wordCount[j].word)==0)
{
h=1;
break;
}
}
if(h==1)
{
wordCount[u].count++;
k=0;
t=1;
continue;
}
wordCount[j].count++;
j++;
k=0;
t=1;
}
else
{
if(c==' '&&t==1)
continue;
else
{
for(u=0;u<j;u++)
相关文档:
c库函数详解——assert
函数名: assert
功 能: 测试一个条件并可能使程序终止
用 法: void assert(int test);
程序例:
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
struct ITEM {
int key;
int value;
};
/* add item to ......
与 &: 任何位用&运算与0结合结果为0,与1结合结果为其本身;
或 | : 任何位用|运算与0结合结果为其本身,与1结合结果为1;
异或 ^ : 任何位用^运算与0结合结果为其本身,与1结合则取反; ......
用过vista的朋友都知道 vista不知由于什么原因很多编译软件都不能正常工作了 vs6.0全部都说有已知的兼容性问题存在
当然你可以装好几个g的vs2005
寡人一直都想自学一门计算机语言
但是苦于找不到编译器
连最简单的hellowold都不能正常编译
汗
不多说
看我弄得
总算能用了
1.下载MinGW
http://sourceforge.net/pro ......
In C++, how do i go about using setenv to set the display? I need to set it like this:
export DISPLAY=0.0
1、setenv("DISPLAY",":0.1",1);
If you're calling the xrandr functions from your C++ program, then I would expect setenv() should work for you. The 3rd argument of 1 tells setenv() to ov ......
问题描述:
C#程序,里面copy了许多原来的代码,所以参差不齐的,很难读,如何才能让代码自动排齐,就象VS 6.0中可以使用快捷键,非常方便.
解答:
ctrl+a,先全选
ctrl+k,ctrl+f,自动排列
或者
ctrl+a,先全选
alt+F8 自动排列 ......