《高級(jí)語言程序設(shè)計(jì)》上機(jī)練習(xí)題

  • 發(fā)布時(shí)間:2024-09-15 16:21:23
  • 來源:本站整理
  • 閱讀:
導(dǎo)讀:
    /*輸出100~999間的所有水仙花數(shù)。如:153=1*1*1+5*5*5+3*3*3,153就是水仙花數(shù)*/    #include <stdio.h>    main()    { int i,a,b,c;    for(i=100;i<1000;i++)    { a=i%10;    b=( (i-a)&a
  /*輸出100~999間的所有水仙花數(shù)。如:153=1*1*1+5*5*5+3*3*3,153就是水仙花數(shù)*/

#include stdio.h

main()

{ int i,a,b,c;

for(i=100;i 1000;i++)

{ a=i%10;

b=( (i-a) % 100 ) / 10;

c=( i-a-b*10 ) /100;

if( i == a*a*a+b*b*b+c*c*c )

printf( %d ,i);

}

}

/*輸出100~200間既是3的倍數(shù)又是5的倍數(shù)的所有數(shù)。*/

#include stdio.h

main()

{ int i;

for(i=100;i 201;i++)

if( i%3==0 i%5==0)

printf( %d ,i);

}

/*從鍵盤上輸入10個(gè)任意整數(shù),如果有3的倍數(shù),求其平均數(shù)*/

#include stdio.h

main()

{ int i,n,s,d;

n=0;

s=0;

for(i=1;i =10;i++)

{ scanf( %d , d);

if( d%3 == 0)

{ n++;

s+=d;

}

}

if(n 0)

printf( result=%d ,s/n);

else

printf( no number );

}

/*輸出100~200間的所有素?cái)?shù)。*/

#include stdio.h

main()

{ int i,j,n;

for(i=100;i =200;i++)

{ for(j=2;j i;j++)

if(i%j ==0)

break;

if(j == i)

printf( %d ,i);

}

}

/*從鍵盤輸入10個(gè)任意整數(shù),輸出其中的最大數(shù)*/

#include stdio.h

main()

{ int i,max,d;

scanf( %d , d);

max=d;

for(i=2;i =10;i++)

{ scanf( %d , d);

if(d max)

max=d;

}

printf( %d ,max);

}

/*編程序計(jì)算1*2*3*4*……*10的值。*/

#include stdio.h

main()

{ int i,s;

s=1;

for(i=1;i =10;i++)

s=s*i;

printf( result=%d ,s);

}

/*從鍵盤上接收任意一串字符,然后倒序輸出。*/

#include stdio.h

main()

{ char a??,c;

int i=0;

c=0;

while(c!=10 c!=13 i 200)

{ scanf( %c , c);

a=c;

i++;

}

i——;

while(i =0)

{ printf( %c ,a;

i——;

}

}

/*從鍵盤輸入10個(gè)數(shù),找出最大數(shù),并指出它是第幾個(gè)數(shù)。*/

#include stdio.h

main()

{ int i,d,max,n;

scanf( %d , d);

max=d;

n=1;

for(i=2;i =10;i++)

{ scanf( %d , d);

if(d max)

{ max=d;

n=i;

}

}

printf( No. %d is the max = %d ,n,max);

}

/*從鍵盤輸入10個(gè)任意整數(shù),輸出其平方和*/

#include stdio.h

main()

{ int i,s,d;

for(i=1;i =10;i++)

{ scanf( %d , d);

s+=d*d;

}

printf( result=%d ,s);

}

/*從鍵盤上接收任意一串字符,統(tǒng)計(jì)其中字母a出現(xiàn)的個(gè)數(shù)。*/

#include stdio.h

main()

{ char c;

int i;

c=0;

i=0;

while(c!=10 c!=13)

{ scanf( %c , c);

if(c=='a')

i++;

}

printf( result=%d ,i);

相關(guān)閱讀