练习题

1

/*the first c programme*/

#include <stdio.h>

main(){

    int num = 1;

    scanf("%d",&num);

    printf("%d",num);

    getch(); 

} 

主要考察输入输出.然后输出结果是:

你输入什么就在屏幕输出什么.

#include "print.h"

int main(void){

      printHello();

      getch();

      return 0;    

}

void printHello(){

         printf("Hello world!\n");

}

主要考察函数调用

 

/*Input 2 numbers output the product*/

#include <stdio.h>

main(){

           int x,y,m;

           printf("Please input x and y\n");      

           scanf("%d%d",&x,&y);  

           m=x*y;

           printf("%d * %d = %d\n",x,y,m);

           getch();

}    

主要考察函数输入输出

//获取从键盘输入字符

scanf("%d%d",&x,&y);

//打印到屏幕字符

printf("%d * %d = %d \n",x,y,m);

/*输入两个浮点数 输出他们中的大数*/

#include <stdio.h>

main(){

     float x,y,c;                /* 变量定义 */

    printf("Please input x and y:\n");  /* 提示用户输入数据 */

    scanf("%f%f",&x,&y);

    c=x>y?x:y;              /* 计算c=max(x,y) */

    printf("MAX of (%f,%f) is %f",x,y,c);   /* 输出c */ 

}    

5

6 输出不同类形状所占字节数

#include <stdio.h>

void main(){

    printf("The bytes of the variables are:\n");

    printf("int:%d bytes\n",sizeof(int));

    /* char型的字节数为1 */

    printf("char:%d byte\n",sizeof(char));

    /* short型的字节数为2 */

    printf("short:%d bytes\n",sizeof(short));

    /* long型的字节数为4 */

    printf("long:%d bytes\n",sizeof(long));

    /* float型的字节数为4 */

    printf("float:%d bytes\n",sizeof(float));

    /* double型的字节数为8 */

    printf("double:%d bytes\n",sizeof(double));

    /* long double型的字节数为8或10或12 */

    printf("long double:%d bytes\n",sizeof(long double));

    getchar();

}

sizeof(number type);

 7 

/* */

#include <stdio.h>

main()

{

    int a=5,b,c,i=10;

    b=a++;

    c=++b;



    printf("a = %d, b = %d, c = %d\n",a,b,c);

    printf("i,i++,i++ = %d,%d,%d\n",i,i++,i++);

    printf("%d\n",++i);

    printf("%d\n",--i);

    printf("%d\n",i++);

    printf("%d\n",i--);

    printf("%d\n",-i++);

    printf("%d\n",-i--);

    getchar();

}

#include <stdio.h>

main (){

     int i,j,n;

     long sum=0,temp=0;      

     printf("Please input a number to n:\n");

     scanf("%d",&n);

     if(n<1){

            printf("the n must no less than 1!\n");  

            return;

     }

     for(i=1;i<=n;i++){

         temp  = 0;

         for(j=1;j<=i;j++){

                 temp += j;

         }

          sum+=temp;

     }

     printf("The sum of the sequence(%d) is %d\n",n,sum);

    getchar();

    getchar();

}        

 

10 010 猜数字游戏

 

你可能感兴趣的:(练习题)