㈠ 請c語言大牛修改一下我的程序(排序改成快排)
#include <stdio.h>
int Partition(int r[],int i,int j) //快速排序的一次劃分
{
int temp=r[i];
while(i<j)
{
while (i<j && r[j]>=temp) j--;
if(i<j)
{
r[i++]=r[j];
}
while (i<j && r[i]<=temp) i++;
if(i<j)
{ r[j--]=r[i];
}
}
r[i]=temp;
return i;
}
void QuickSort(int r[],int i,int j) //快速排序
{
if(i<j)
{
int pivot=Partition(r,i,j);
QuickSort(r,i,pivot-1);
QuickSort(r,pivot+1,j);
}
}
main()
{
int i,q;
int a[1000];
printf("Enter the num of array:\n");
scanf("%d",&q);
printf("Enter the member of array:\n");
for(i=0;i<q;i++)
scanf("%d",&a[i]);
QuickSort(a,0,q-1);
printf("QuickSort:\n");
for(i=0;i<q;i++)
{
printf("%d ",a[i]);
}
printf("\n");
}
已測試 比如
Enter the num of array:
10
Enter the member of array:
6 3 8 2 5 9 5 2 5 10
輸出
QuickSort:
2 2 3 5 5 5 6 8 9 10
㈡ 郝斌老師的c語言講得怎麼樣
郝斌老師講的c語言基本都是基礎知識,非常適合初學者,對於初學者來說可能是非常好的入門教程,郝斌老師講課詼諧幽默,而且也都是從原理上給學生講課,這就讓從沒學過計算機基礎的人也可以掌握c語言,理解c語言的運行機制,同時郝斌老師的課程還培養出非常多的大牛,為此這些大牛還組建了郝斌老師教學的基地,如果你是自學的話,那麼一定要前往斌軟社區和你的同門師兄弟一起交流切磋,這樣你可以成長得更快。
㈢ 找一位C語言大牛。本人自學經常遇到問題、
其實c語言並沒有想像中的那麼困難,從基礎學起,一點一點看基礎。最重要的是動手寫,看懂和動手寫出來之間的差距是很大的。先從模仿程序開始,比方說寫出最簡單的hello world 開始。慢慢的到復雜一些的循環啊之類的,你的信心會隨著這個過程慢慢提高的,相信你會找到寫程序的樂趣。
㈣ 求C語言大牛解答~~很著急~`~
第一題
#include <stdio.h>
#include<string.h>
int IsPrime(int n)
{
int i;
if(n<2)//小於2不是素數
return 0;
for(i=2;i<n;i++)//拿2到n-1的去試除
{
if(n%i==0)return 0;//有因子,不是素數,退出
}
return 1;
}
int main()
{
int n;
printf("Please input n:");
scanf("%d",&n);
for(n++;;n++)
{
if(IsPrime(n))break;
}
printf("%d\n",n);
return 0;
}
第二題
#include <stdio.h>
#include<string.h>
int main()
{
int a[5],b[5],tmp,i;
for(i=0;i<5;i++)scanf("%d",&a[i]);
for(i=0;i<5;i++)scanf("%d",&b[i]);
for(i=0;i<5;i++)
{
tmp=a[i];
a[i]=b[i];
b[i]=tmp;
}
for(i=0;i<5;i++)printf("%5d",a[i]);
puts("");
for(i=0;i<5;i++)printf("%5d",b[i]);
puts("");
return 0;
}
㈤ C語言大牛幫我 char c; #include<stdio.h>
我暈,這三條語句是最基本的了,你敢看如此長的程序代碼,沒理由不懂它們的意思:
char c; //定義一個char型變數,變數名為c
printf("Input a character:"); //輸出一行字元(字元串),內容是Input a character:,中文 //意思是:請輸入一個字元:
c=getchar(); //把從鍵盤上鍵入的字元賦值給變數c
㈥ 急!!求C語言大牛解答兩道題~~~!!!
/*******************************************************************************
從鍵盤任意輸入一個整數m,若m不是素數,則對m進行質因數分解,
並將m表示為質因數從小到大順序排列的乘積形式輸出,否則輸出
"It is a prime number\n"。例如,用戶輸入90時,程序輸出90 = 2 * 3 * 3 * 5;
用戶輸入91時,程序輸出"It is a prime number\n"。
素數(Prime Number),又稱為質數,它是不能被1和它本身以外的其他整數整除的正整數。
按照這個定義,負數、0和1都不是素數,而17之所以是素數,是因為除了1和17以外,
它不能被2~16之間的任何整數整除。
要用函數哦。
*******************************************************************************/
#include<stdio.h>
#include<math.h>
/**
*遞歸函數,輸出因子的乘積
*/
void printProct(long number)
{
long i;
for(i = 2; i <= sqrt(number); i++) {
if(number % i == 0)
{
long biggestFactor = number / i; //最大因子
printf("%ld * ", i);
printProct(biggestFactor);
break;
}
}
if(i > sqrt(number)) //如果不能因式分解,就輸出本身
{
printf("%ld\n", number);
}
}
/**
*判斷是否為素數的函數,是返回1,否返回0
*/
int isPrime(long number)
{
long i;
for(i = 2; i <= sqrt(number); i++) {
if(number % i == 0) {
return 0;
}
}
return 1;
}
int main()
{
long number;
int i;
printf("請輸入一個數:");
scanf("%ld", &number);
if(isPrime(number) == 1)
{
printf("It is a prime number\n");
}
else
{
printf("%ld = ", number);
printProct(number);
}
}
/*
如果一個正整數m的所有小於m的不同因子(包括1)加起來正好等於m本身,
那麼它就被稱為完全數(Perfect Number)。例如,6就是一個完全數,
是因為6 = 1 + 2 + 3。請編寫一個判斷完全數的函數IsPerfect(),
函數功能:判斷完全數,若函數返回0,則代表不是完全數,若返回1,則代表是完全數。
在主調函數中,輸入一個數,調用子函數IsPerfect(),根據函數的返回值,判斷從鍵盤
輸入的整數是否是完全數。
*/
#include<stdio.h>
#include<math.h>
int isPerfect(long number)
{
long i;
long sum = 1;
long factorPool[1000]; //因子池數組
int j = 0; //因子池數組下標
for(i = 2; i <= sqrt(number); i++)
{
if(number % i == 0)
{
factorPool[j++] = i;
factorPool[j++] = number / i;
sum += i;
sum += number / i;
}
}
if(sum == number)
{
int k;
printf("%ld = 1 + ", number);
for(k = 0; k < j - 1; k++)
{
printf("%ld + ", factorPool[k]);
}
printf("%ld", factorPool[k]);
return 1;
}
else
{
return 0;
}
}
int main()
{
long number;
printf("請輸入一個數:");
scanf("%ld", &number);
if(isPerfect(number))
{
printf(",所以是完全數。\n");
}
else
{
printf("%d 不是完全數。\n", number);
}
}
順便提一下樓上在第二題有誤,33550336是一個完全數,用樓上程序去判斷程序直接崩潰
㈦ C語言哪個老師好點
譚浩強,他的教材C語言程序設計是使用最廣泛的。
㈧ C語言大牛請進,排序問題,不知道錯在哪
#include<stdio.h>
#include<stdlib.h>
int main ()
{
long int n;
long int a[100],b[100][100];
long int i,j,counter;
long int hold;
scanf("%ld", &n);
for( i = 0; i < n; i++ )
{
scanf("%ld", &a[i]);
for( counter = 0; counter < a[i]; counter++ )
scanf("%ld", &b[i][counter]);
}
printf("\n");//輸入跟輸出分開一點,好看結果
for( i = 0; i < n; i++ )
{
for( counter = 0; counter < a[i]-1; counter++ )
{
//for( j = 0; j < a[i]-2; j++ ) //****** a[i]-2錯, 沒推到尾
for( j = 0; j < a[i]-1-counter; j++) //當然不必每次推到尾改為 a[i]-1-counter 就好
{
if( b[i][j] > b[i][j+1] )
{
hold = b[i][j];
b[i][j] = b[i][j+1];
b[i][j+1] = hold;
}
}
}
for( counter = 0; counter < a[i]; counter++ )
printf("%ld\n", b[i][counter]);
}
system("pause");
return 0;
}
//錯在帶星號的行
㈨ 請教C語言大牛一個關於宏的問題啊~~
單從FD(m,fd)->type=XXXXXXX;這句而言就是直接修改fd所指向的mio_priv_fd_st類型對象的type成員而已。
type這個成員代表著當前FD(m,fd)的類型(或者狀態)。
你貼的程序很零散,暫時只能看出這么多。不知道你這個fd是快閃記憶體呢還是軟碟機呢?
㈩ C語言有哪些老師教
我就是自學的C語言,給你說說我自學c語言的過程,剛上大一的時候就聽說下半學期要開語言的課程。於是,假期一回家,買了一本譚浩強的C語言程序設計來看,反復看了有兩遍吧,第一遍粗看,第二遍細看,書上有程序,邊看邊在 VC6.0裡面編譯!下學期到了學校後,又在網上的各大學C的論壇里學習,看看視頻教程,我看過黑客基地的C語言基礎教程,還有小甲魚的視頻教程,還有好多呢,我自己都忘了,最後我覺得吧,小甲魚的講得還不錯,除了好聽的聲音外,他的視頻是跟著書本的,好像就是譚浩強的C程序設計呢?還有講匯編的。聲明我不是計算機專業的。下學期考試反正我是考了第一,當然是C語言了,呵呵!現在感覺還不錯。我要告訴你學習C語言只是基礎而已,重要在於他的應用,而且很枯燥,不過沒辦法,等你把基礎掌握了,可以看看C語言關於Windows方面的編程,他是C的一個重要的應用啊,也是鞏固C和提高C語言興趣的重要途徑呢!最後給你建議:買一本譚浩強的C語言程序設計再看看小甲魚的視頻教程,建議你必須先把全書瀏覽一遍或是多遍最好,再去看視頻,這樣效果會好的多的。總之就是教材加上視頻再加上多逛一些論壇,比如VC驛站等等。你要相信只要你花時間去認真學習,肯定會懂的,至於你說精通,C博大精深,沒有多少人敢說他精通C語言,學得自己夠用就行了!