1. 誰能給我一個80行的c語言程序。要簡單點的,大一新生,拜託了
我剛寫的,給你熱身,,
#include <stdio.h>
void move(char *p,int i);
void remove(char *a,char f);
int main()
{
int i;
char a[60],f;
puts("輸入字元串:");
gets(a);
puts("輸入要刪除的字元:");
f=getchar();
remove(a,f);
puts("刪除後:");
puts(a);
puts("輸入需要互換的前幾個數:");
scanf("%d",&i);
move(a,i);
puts("互換後:");
puts(a);
return 0;
}
void remove(char *a,char f)
{ char *b=a;
while(*b!='\0')
{
if(*b!=f) { *a=*b;a++;}
b++;
}
*a=*b;//把字元串標志寫進去
}
void move(char *p,int i)
{
char *a=p+i,*b=a,f;
while(p!=a) //a記錄開始位置 b也記錄開始位置保持不變 作為循環結束條件
{
f=*a;
*a=*p;//互換 把第一個移到開始位置 把開始位置的字元作為前面字元出現
*p=f;
while(*(a+1)!='\0')//通過循環把它傳到最後面 那麼此時開始位置又出現新的字元 注意是*(a+1)!='\0'而不是*a!='\0'
{
f=*a;
*a=*(a+1);
*(a+1)=f;
a++;
}
a=b;//把a置初始位置
p++;//移動下一個需要移動到最後面的字元
}
}
2. 求一個80--100行左右的簡單些的C語言程序!
可以對輸入的學生信息:學號 名字 性別 分數,然後根據分數排名次輸出,都學完C了這個應該可以做出來吧
3. 急求一個c語言的大約80行的代碼,內容不限,易理解就好(是c語言,不是c++)謝謝
include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define NUM 10
/*int perfect_num(int num){
int x=1,y=0;
while(x<num && x>0){
if(num%x==0){
y=y+x;
}
x=x+1;
}
printf("y=%d\n",y);
if(y==num){
return num;
}
}
int main(){
int return_num=0,num=1;
for(;num<NUM;num++){
return_num=perfect_num(num);
printf("perfect num is %d\n",return_num);
}
}
int main(){
int a=2,b;
b=(2*a,3,a-3);
printf("\nb=%d\n",b);
}
int main(){
int a=2,b=1,c=3;
printf("最大值為%d\n",a>b?(a>c?a:c):(b>c?b:c));
}
int main(){
int a=11;
int b=0x11;
printf("%d\n",a>b?a:b);
}
#include <stdio.h>
int main()
{
int x; double y;
while(scanf("%d",&x)!=EOF)
{
switch (x/100000)
{
case 0:
case 1:y=x*0.1;break;
case 2:y=100000*0.1+100000*0.075;break;
case 3:
case 4:y=100000*0.1+100000*0.075+200000*0.1+200000*0.05;break;
case 5:
case 6:y=100000*0.1+100000*0.075+200000*0.1+x-200000*0.05+200000*0.1+400000*0.03;break;
case 7:
case 8:
case 9:
case 10:y=100000*0.1+100000*0.075+200000*0.1+200000*0.05+200000*0.1+400000*0.03+200000*0.1+600000*0.015;break;
default:y=100000*0.1+100000*0.075+200000*0.1+200000*0.05+200000*0.1+400000*0.03+1000000*0.01;break;
}
printf("%.0f\n",y);
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main(){
srand(5);
printf("%d\n",rand());
printf("%d\n",rand());
printf("%d\n",rand());
printf("%d\n",rand());
}
//約瑟夫環問題
void main(){
int total,num,last,i;
i=0;last=0;
printf("請輸入人數\n");
scanf("%d",&total);
printf("請輸入數數的數字\n");
scanf("%d",&num);
for(i=2;i<=total;++i){
last=(last+num)%i;
printf("i=%d,last=%d\n",i,last);
}
printf("The last one is:%d\n",last+1);
}
4. 急求八十行的c語言程序一份
如果只要行數的話,連續80行的printf("hi\n");可以嗎?或者用80個printf寫一段話?
5. 求一簡單的c語言編程題80行左右 大一用的 c++環境下運行的 簡單點的
以下是統計26個英文小寫字母出現的次數
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void Stat(char *str,int count[])
{
int i;
for(i=0;i<26;i++)count[i]=0;
for(i=0;i<strlen(str);i++)
{
if(str[i]=='a')count[0]++;
else if(str[i]=='b')count[1]++;
else if(str[i]=='c')count[2]++;
else if(str[i]=='d')count[3]++;
else if(str[i]=='e')count[4]++;
else if(str[i]=='f')count[5]++;
else if(str[i]=='g')count[6]++;
else if(str[i]=='h')count[7]++;
else if(str[i]=='i')count[8]++;
else if(str[i]=='j')count[9]++;
else if(str[i]=='k')count[10]++;
else if(str[i]=='l')count[11]++;
else if(str[i]=='m')count[12]++;
else if(str[i]=='n')count[13]++;
else if(str[i]=='o')count[14]++;
else if(str[i]=='p')count[15]++;
else if(str[i]=='q')count[16]++;
else if(str[i]=='r')count[17]++;
else if(str[i]=='s')count[18]++;
else if(str[i]=='t')count[19]++;
else if(str[i]=='u')count[20]++;
else if(str[i]=='v')count[21]++;
else if(str[i]=='w')count[22]++;
else if(str[i]=='x')count[23]++;
else if(str[i]=='y')count[24]++;
else if(str[i]=='z')count[25]++;
}
}
int main(void)
{
char str[10000];
int i,count[26];
printf("請輸入a~z的字元串:\n");
gets(str);
Stat(str,count);
for(i=0;i<26;i++)
printf("%c:%d\n",i+'a',count[i]);
system("pause");
return 0;
}
祝你愉快!
6. C語言80行左右的編程
以前寫的在給出n_gs=6個aa[]數中挑選n_js=3個數,其加減運算後的和的絕對值在n_fw1=8,n_fw2=10 范圍內所有組合,輸出運算過程,其最後結果輸出到jg.txt
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int no[40],aa[]={1,2,3,4,5,6};
int MAXSIZE = 40;
unsigned short n_js=3,n_gs=6;
float n_fw1=8,n_fw2=10;
float n_l1=0,n_l2=0,n_l3=0,n_sum;
float n_fw11,n_fw12;
int N,M;
int A[80], B[80],str[40],ss[40];
char www3[80];
char www1='X',www2='=';
FILE *fp;
void comb_all()
{
unsigned short i,j,k,l;
short bound;
n_sum = 0;
for (i=0 ; i<n_js; ++i)
{ str[i]=B[i];
ss[i]=-1;
n_sum=n_sum+B[i];
}
n_fw12=(n_sum-n_fw1)/2;
n_fw11=(n_sum-n_fw2)/2;
bound = (1 << n_js);
for (i = 1; i < bound; ++i)
{
unsigned short mask = 1;
n_l1 = 0;
for (j = 0; j < n_js; ++j)
{
if (i & mask)
ss[j]=j;
www3[j]='+';
mask <<= 1;
}
for (k=0;k<n_js;++k)
{ if (ss[k] > -1)
{
n_l1=n_l1+str[k];
www3[k]='-';
ss[k]=-1;
}
}
if ((n_l1>n_fw11)&&(n_l1<n_fw12))
{/*輸出*/
for (l=0 ;l<n_js;++l)
{ fprintf(fp,"%c%c%d",www3[l],www1,A[l]+1);
}
fprintf(fp,"%c%f\n",www2,n_sum-n_l1*2);
}
}
}
/* 待刪除 */
void Print()
{
int i,l;
float n_s1=0;
for (i = 0; i < n_js; ++i)
{n_s1=n_s1+B[i];
printf("%d %d---", B[i],A[i]);}
printf("fffffffffff\n");
if (n_s1> n_fw2)
{ comb_all();}
else if (n_s1>n_fw1)
{for (l=0 ;l<n_js;++l)
{ fprintf(fp,"%c%c%d",www3[l],www1,A[l]+1);
}
fprintf(fp,"%c%f\n",www2,n_s1);}
}
void Com(int n, int m)
{
int i;
for (i = n; i >= m; --i)
{
B[m] = aa[i];
A[m] = no[i];
if (m > 0)
Com(i-1,m-1);
else
Print();
}
}
/* 待刪除 */
int main()
{
int i;
if((fp=fopen("jg.txt","w"))==NULL)
{printf("cannot open this file \n");
exit(0);
}
for(i=0;i<40;i++) /*對A[N]進行初始化,*/
{
no[i]=i;
A[i]=i;
www3[i]='+';
}
if (n_gs > MAXSIZE)
return 1; /*越界*/
Com(n_gs-1,n_js-1);
/* comb_all();*/
fclose(fp);
return 0;
}
7. 急!求一c語言程序,50-80行的,最好是原創,簡易點的
親,以下為一簡單的猜數游戲,你可以看看:
#include"stdio.h"
#include"stdlib.h"
#include"time.h"
void main()
{
long a,b,c,d,i,f;
char e;
there:
printf("下面開始猜數游戲,請你選擇你要猜的范圍\n");
printf("范圍最小為50,且你有10次機會\n");
here:
printf("請選擇你要猜的下限:");
while((scanf("%ld",&a))!=1)
{
getchar();
printf("對不起,你輸入的不是整數,請輸入一個整數做為下限\n");
}
printf("請選擇你要猜的上限:");
while((scanf("%ld",&b))!=1)
{
getchar();
printf("對不起,你輸入的不是整數,請輸入一個整數做為上限\n");
}
if(b<a)
{
f=a;
a=b;
b=f;
}
if(b-a<50)
{
printf("對不起,你輸入的范圍小於50,請重新輸入上下限\n");
goto here;
}
srand(time(NULL));
c=rand()%(b-a+1)+a;
for(i=1;i<=10;i++)
{
printf("請給出你的第%ld次選擇:",i);
if((scanf("%ld",&d))!=1)
{
getchar();
printf("對不起,您輸入的數據不符合游戲規則,請輸入%ld到%ld的整數\n",a,b);
printf("您還有%ld次機會,請再接再厲\n",10-i);
}
else if(d>b||d<a)
{
printf("對不起,您猜的數超出了范圍,請輸入%ld到%ld的整數\n",a,b);
printf("您還有%ld次機會,請再接再厲\n",10-i);
}
else if(d>c)
{
if(d-c<10)
{
printf("您猜的數大了一點點,勝利就在眼前\n");
printf("您還有%ld次機會,請再接再厲\n\n",10-i);
}
else
{
printf("你猜的數過大了\n");
printf("您還有%ld次機會,請再接再厲\n\n",10-i);
}
}
else if(d<c)
{
if(c-d<10)
{
printf("您猜的數小了一點點,勝利就在眼前\n");
printf("您還有%ld次機會,請再接再厲\n\n",10-i);
}
else
{
printf("你猜的數過小了\n");
printf("您還有%ld次機會,請再接再厲\n\n",10-i);
}
}
else
{
printf("\n\n恭喜你,猜對了!\n");
printf("你是否還想再玩這個游戲?\n\n");
printf("如果想繼續玩,請按『Y』(不區分大小寫)\n");
printf("如果不想再玩了,請按其他任意鍵退出\n");
printf("您的選擇是:");
getchar();
scanf("%c",&e);
if(e=='Y'||e=='y')
goto there;
else
break;
}
}
if(i==11){
printf("對不起,您的機會已經用完了\n");
printf("您可以選擇重新再玩或退出\n");
printf("按『Y』(不區分大小寫)是重新再玩,其他任意鍵退出\n");
printf("您的選擇是:");
getchar();
scanf("%c",&e);
if(e=='Y'||e=='y')
goto there;
}
}
8. C語言不少於80行的程序語句
#include<stdio.h>
intmain(void)
{
inti;
intyear,total,total1,total2;
intmon1,mon2;
intday1,day2;
intyear1[12]={31,28,31,30,31,30,31,31,30,31,30,31};
intyear2[12]={31,29,31,30,31,30,31,31,30,31,30,31};
total1=total2=0;
printf("請輸入您要計算哪一年:");
scanf("%d",&year);
if(year%4==0&&year%100!=0||year%400==0)//判斷此年是否是閏年,如果是閏年執行下面的語句
{
printf("%d年是閏年. ",year);
printf("請輸入第一個月份:");
while(scanf("%d",&mon1)==1)
{
if(mon1>12||mon1<=0)
{
printf("您的輸入有誤,請重新輸入! ");
printf("請輸入第一個月份:");
}
else
break;
}
printf("請輸入此月的第幾天:");
while(scanf("%d",&day1)==1)
{
if(mon1==2)
{
if(day1>29||day1<=0)//閏年二月有29天
{
printf("您的輸入有誤,請重新輸入! ");
printf("請輸入此月的第幾天:");
}
else
break;
}
else
break;
}
printf("請輸入第二個月份:");
while(scanf("%d",&mon2)==1)
{
if(mon2>12||mon2<=0)
{
printf("您的輸入有誤,請重新輸入! ");
printf("請輸入第二個月份:");
}
else
break;
}
printf("請輸入此月的第幾天:");
while(scanf("%d",&day2)==1)
{
if(mon2==2)
{
if(day2>29||day2<=0)
{
printf("您的輸入有誤,請重新輸入! ");
printf("請輸入此月的第幾天:");
}
else
break;
}
else
break;
}
for(i=0;i<mon1-1;i++)
total1+=year1[i];
total1+=day1;
for(i=0;i<mon2-1;i++)
total2+=year1[i];
total2+=day2;
if(total1>total2)
total=total1-total2;
else
total=total2-total1;
printf("這兩個日期共相差%d天! ",total);
}
else//不是閏年的情況
{
printf("%d年不是閏年. ",year);
printf("請輸入第一個月份:");
while(scanf("%d",&mon1)==1)
{
if(mon1>12||mon1<=0)
{
printf("您的輸入有誤,請重新輸入! ");
printf("請輸入第一個月份:");
}
else
break;
}
printf("請輸入此月的第幾天:");
while(scanf("%d",&day1)==1)
{
if(mon1==2)//平年二月有28天
{
if(day1>28||day1<=0)
{
printf("您的輸入有誤,請重新輸入! ");
printf("請輸入此月的第幾天:");
}
else
break;
}
else
break;
}
printf("請輸入第二個月份:");
while(scanf("%d",&mon2)==1)
{
if(mon2>12||mon2<=0)
{
printf("您的輸入有誤,請重新輸入! ");
printf("請輸入第二個月份:");
}
else
break;
}
printf("請輸入此月的第幾天:");
while(scanf("%d",&day2)==1)
{
if(mon2==2)
{
if(day2>28||day2<=0)
{
printf("您的輸入有誤,請重新輸入! ");
printf("請輸入此月的第幾天:");
}
else
break;
}
else
break;
}
for(i=0;i<mon1-1;i++)
total1+=year2[i];
total1+=day1;
for(i=0;i<mon2-1;i++)
total2+=year2[i];
total2+=day2;
if(total1>total2)
total=total1-total2;
else
total=total2-total1;
printf("這兩個日期共相差%d天! ",total);
}
return0;
}
這個應該不會有雷同! 而且夠長
9. 求一C語言程序,80行足矣,隨便什麼不用太難~。
看看行不行
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _employee
{
int number;
char * name;
int sex;
int age;
}em;
struct simple
{
char * name;
int age;
};
#define NUM 10
em array[NUM];
int nowCount = 0;
int delEm(int num)
{
int flag = 0;
int i, j;
for(i = 0; i < nowCount; i++)
{
if(array[i].number == num)
{
for(j = i + 1; j < nowCount; ++j)
{
array[j-1] = array[j];
}
flag = 1;
--nowCount;
}
}
return flag;
}
int insert(em e)
{
if(nowCount < NUM)
{
array[nowCount] = e;
++nowCount;
return 1;
}
return 0;
}
void input(em *e)
{
printf("請輸入職工編號:");
scanf("%d", &(e->number));
printf("請輸入職工姓名:");
e->name = (char*)malloc(15);
memset(e->name, 0, 15);
scanf("%s", e->name);
printf("請輸入職工性別(1代表男,0代表女):");
scanf("%d", &(e->sex));
printf("請輸入職工年齡:");
scanf("%d", &(e->age));
printf("\n");
}
void print()
{
int i;
printf("\n現在共有%d個職工的信息.\n", nowCount);
for(i = 0; i < nowCount; ++i)
{
printf("第%d個職工的信息如下:\n", i + 1);
printf("職工序號:%d\n", array[i].number);
printf("職工姓名:%s\n", array[i].name);
printf("職工性別:%s\n", (array[i].sex ? "男" : "女"));
printf("職工年齡:%d\n", array[i].age);
printf("\n");
}
}
void main()
{
int flag = 1;
int num;
em e;
int choice = 0;
while(flag)
{
printf("\n");
printf("--------------------菜單---------------------\n");
printf("1.輸入職工信息\n");
printf("2.顯示現有職工信息\n");
printf("3.刪除某職工信息\n");
printf("4.退出\n");
printf("請輸入操作代號:");
scanf("%d", &choice);
printf("\n");
switch(choice)
{
case 1:
printf("現在共有%d個職工的信息,共可以存%d個,最多還可以輸入%d個\n", nowCount, NUM, NUM - nowCount);
if(nowCount == NUM)
{
printf("人數已經達上限%d個.不再接受輸入", NUM);
break;
}
input(&e);
insert(e);
break;
case 2:
print();
break;
case 3:
printf("請輸入要刪除的職業序號:");
scanf("%d", &num);
if(delEm(num))
printf("刪除完成\n");
else
printf("刪除失敗\n");
break;
case 4:
flag = 0;
break;
default:
break;
}
}
getchar();
}
10. 求一個80行C語言程序
#include "time.h"
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
main()
{
char c;
clock_t start,end;
time_t a,b;
double var;
int i,guess;
srand(time(NULL));
printf("do you want to play it.('y' or 'n') \n");
loop:
while((c=getchar())=='y')
{
i=rand()%100;
printf("\nplease input number you guess:\n");
start=clock();
a=time(NULL);
scanf("%d",&guess);
while(guess!=i)
{
if(guess>i)
{
printf("please input a little smaller.\n");
scanf("%d",&guess);
}
else
{
printf("please input a little bigger.\n");
scanf("%d",&guess);
}
}
end=clock();
b=time(NULL);
printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2);
printf("\1: it took you %6.3f seconds\n\n",difftime(b,a));
if(var<15)
printf("\1\1 You are very clever! \1\1\n\n");
else if(var<25)
printf("\1\1 you are normal! \1\1\n\n");
else
printf("\1\1 you are stupid! \1\1\n\n");
printf("\1\1 Congralations \1\1\n\n");
printf("The number you guess is %d",i);
}
printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");
if((c=getch())=='y')
goto loop;
}