㈠ c語言練習題
100÷7等於14於二.所以應該是上ban
㈡ C語言綜合練習題
1. 在C程序中,只能用於整型變數的運算符是___ 求余(%)___。2. 在C語言中,char類型變數占 2 個位元組。3. 若a已定義為double類型,請寫出從鍵盤給a輸入數據的語句 scanf("%lf",a); 。4. 為使以下程序能正確運行,請填空。include<stdio.h> include<math.h> main(){ double x, y; scanf("%lf%lf",x,y); printf("y=%f\n", pow(x,y));}5. 以下程序執行後的輸出結果是 -2 。 main() { int m=3,n=4,x; x=-m++; x=x+8/++n; printf("%d\n",x); }6. 以下程序的輸出結果是 10 20 0 。 main() { int a,b,c; a=10; b=20; c=(a%b<1)(a/b>1); printf("%d %d %d\n",a,b,c); }7. 以下程序中調用fun函數,對主函數x和y中的值進行對調。請填空。void fun( double *a, double *b){ double x;x=*a; *a=*b ; *b=x ; }main(){ double x,y;printf(「Enter x, y : 「); scanf(「%lf%lf」,x,y);fun( x,y);printf(「x=%f y=%f\n」,x,y );}8. C語言規定:字元串以 '\0' 作為結束標志。9. 以下程序的輸出結果是 3 。 long fun( int n){ long t;if ( n==1 n==2 ) t=1;else t=fun(n-1) + fun(n-2);return ( t );}main( ){ printf(「%d\n」,fun(4) );}10. 設有定義:struct date{ int year, month, day ; } d1;請寫出利用輸入語句,為變數d1中的year成員從鍵盤輸入數值的語句 scanf ("%d",(d1.year)); 。
㈢ 用C語言編寫一種循環結構占滿504M的內存.
#include stdio.h
int main()
{
int step = 1024; //1K
long i;
for(i=0; i<1024*504; i++) //循環504K次。這個有問題!這是循環了1024*504此,不是504此,應將i++改為 i+=step
{
malloc(step); //每次分配1K內存,總共504K*1K=504M
}
return 0;
}
㈣ c語言練習題
a = -20; // a是有符號整型,賦值後值為-20
c = 19.5; // c是無符號整型,賦值後值為19
a+c,兩者類型不同,要進行整數類型提升,a會被提升為無符號整型,設int為4個位元組,則-20對應的無符號整型值是4294967276,因此a+c=4294967276+19=4294967295,這個值為真,且大於0
因此(a+c)?c:a將返回c的值19,d=19
((a+c)>0)?a:c將返回a的值-20,b=-20
㈤ 用c語言,數據結構的書,求練習5 5.1
#include <iostream>
using namespace std;
int main()
{
int n = 0;
cin>>n;
int *a = (int *)malloc(sizeof(int)*n);
for(int i = 0;i<n;i++)
cin>>a[i];
double sum = 0;
for(int i = 0;i<n;i++ )
sum += a[i];
cout<<sum/n;
return 0;
}
㈥ C語言簡單的練習題
在C語言中逗號「,」也是一種運算符,稱為逗號運算符。 其功能是把兩個表達式連接起來組成一個表達式, 稱為逗號表達式。
其一般形式為:
表達式1,表達式2
其求值過程是分別求兩個表達式的值,並以表達式2的值作為整個逗號表達式的值。
1) 逗號表達式一般形式中的表達式1和表達式2 也可以又是逗號表達式。
例如:
表達式1,(表達式2,表達式3)
形成了嵌套情形。因此可以把逗號表達式擴展為以下形式:
表達式1,表達式2,…表達式n
整個逗號表達式的值等於表達式n的值。
2) 程序中使用逗號表達式,通常是要分別求逗號表達式內各表達式的值,並不一定要求整個逗號表達式的值。
並不是在所有出現逗號的地方都組成逗號表達式,如在變數說明中,函數參數表中逗號只是用作各變數之間的間隔符。
所以結果是7,2,3;
注意,最後的(x+5)只是用x參與運算,並沒有改變x的值
㈦ c語言編程:練習題。
#include<iostream.h>
int main()
{
int i,j,t;
int a[10],b[10];
cout<<"請輸入第一個數組:"<<endl;
for(i=0;i<10;i++)
cin>>a[i];
for(i=1;i<10;i++)
for(j=0;j<9;j++)
if(a[i]<a[j])
{t=a[i];a[i]=a[j];a[j]=t;}
cout<<"排序後的第一個數組為:"<<endl;
for (i=0;i<10;i++)
cout<<a[i]<<" ";
cout<<endl;
cout<<"請輸入第二個數組:"<<endl;
for(j=0;j<10;j++)
cin>>b[j];
for(i=1;i<10;i++)
for(j=0;j<9;j++)
if(b[i]<b[j])
{t=b[i];b[i]=b[j];b[j]=t;}
cout<<"排序後的第二個數組為:"<<endl;
for (i=0;i<10;i++)
cout<<b[i]<<" ";
cout<<endl;
for(i=0;i<10;i++)
a[i]=a[i]+b[i];
cout<<"兩數組的和為:"<<endl;
for (i=0;i<10;i++)
cout<<a[i]<<" ";
cout<<endl;
return 0;
}
㈧ C語言的練習
1
int n = 0, c;
c = getchar();
while(!eof())
{
if(isdigit(c)) n++;
c=getchar();
}
2
int n, i;
int count = 0;
static int not_prim[101];
for (n = 2; n <= 10; ++ n)
for (i = 2; i * n <= 100; ++ i)
not_prim[i*n] = 1;
for (i = 2; i <= 100; ++i)
{
if (0 == not_prim[i])
{
printf("\t%d", not_prim[i]);
++count;
}
if (0 == count % 5)
putchar("\n");
}
㈨ C語言練習題
2,
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int temp;
temp=a;
a=b;
b=temp;
cout<<a<<b;
return 0;
}
3
#include<iostream>
using namespace std;
int main()
{
int t,a,b,c;
cin>>a,b,c;
if(a<b)
{t=a;
a=b;
b=t;
}
if(a<c)
{
t=a;
a=c;
c=t;
}
if(b<c)
{
t=b;
b=c;
c=t;
}
cout<<"a="<<a<<"b="<<b<<"c="<<c;
return 0;
}