A-A+

C/Cplusplus some functions

2012年02月13日 C++知识 暂无评论 阅读 21 次
 One-atoi:

 /*atoi example*/   
#include 
#include 

int main ()
{
  int i;
  char szInput [256];
  printf ("Enter a number: ");
  fgets ( szInput, 256, stdin );
  i = atoi (szInput);
  printf ("The value entered is %d. The double is %d.\n",i,i*2);
  return 0;
}

Two-itoa:

// itoa example

#include 
#include 

int main ()
{
  int i;
  char buffer [33];
  printf ("Enter a number: ");
  scanf ("%d",&i);
  itoa (i,buffer,10);
  printf ("decimal: %s\n",buffer);
  itoa (i,buffer,16);
  printf ("hexadecimal: %s\n",buffer);
  itoa (i,buffer,2);
  printf ("binary: %s\n",buffer);
  return 0;
}

Three-char->string&&string->char:

#include 

#include 

using namespace std;

int main()

{

 string x,temp;
 char p[15]="i am a boy!";
 cin>>x;
 cout<

#include 
#include 
using namespace std;
int main()
{
 char str[20];
 sprintf(str,"%d",168);
 cout<
#include 

int main ()
{
  printf ("ceil of 2.3 is %.1lf\n", ceil (2.3) );
  printf ("ceil of 3.8 is %.1lf\n", ceil (3.8) );
  printf ("ceil of -2.3 is %.1lf\n", ceil (-2.3) );
  printf ("ceil of -3.8 is %.1lf\n", ceil (-3.8) );
  return 0;
}
Output:
ceil of 2.3 is 3.0
ceil of 3.8 is 4.0
ceil of -2.3 is -2.0
ceil of -3.8 is -3.0
 
标签:

给我留言

Copyright © C/C++程序员之家 保留所有权利.   Theme  Ality 浙ICP备15011757号-3

用户登录