请教几道C语言编程题,急用 请教几道C语言的编程题

\u51e0\u9053c\u8bed\u8a00\u7f16\u7a0b\u9898\uff0c\u6025\u7528\uff01\uff01\uff01\uff01

\u90fd\u662f\u57fa\u7840\u7684\u9898\u5440~
2
#include
main()
{
int a[3][4]={{2,546,34,32},{0,-12,5,-124},{43,57,36,547}};
int i,j,max,x=0,y=0;
max = a[0][0];
for(i=0;i!=3;i++)
for(j=0;j!=4;j++)
if(a[i][j]>max)
{
max=a[i][j];
x=i;
y=j;
}
printf("a[%d][%d]=%d",x,y,max);

}\u001a

\u5192\u6ce1\u6cd5\u6392\u5e8f\u7684\u8fd0\u7b97\u6b21\u662fN/2\u4e0d\u662f\u6700\u6162\u7684\uff01\uff01\uff01



\u6297\u8bae\uff01\uff01~~~~~~

1.
#include <stdio.h>
main()
{
int x,y;
printf("please input x :");
scanf("%d",&x);
/*下面三句可以用这一句代替: y=(x<0)?(x-1):(x=0?0:1);*/
if(x<0) y=x-1;
else if(x==0) y=0;
else y=1;
printf("the value of y=%d",y);
getch();
}
2.
#include <stdio.h>
main()
{
int h,i,s;
s=560;
h=s/60;
i=s%60;
printf("%d minutes equals %d hours %d minutes",s,h,i);
getch();
}
3.
#include <stdio.h>
main()
{
int a,b,c,d,max,temp;
max=0;
temp=0;
printf("please input the value of a,b,c,d:\n");
scanf("%d%d%d%d",&a,&b,&c,&d);
/*以下六行可被这一行代替: max=(a>b?a:b)>(c>d?c:d)?(a>b?a:b):(c>d?c:d); */
if(a>=b)max=a;
else max=b;
if(c>=d)temp=c;
else temp=d;
if(max<temp)max=temp;

printf("the max of a,b,c,d is %d ",max);
getch();
}
4
#include <stdio.h>
main()
{
char c;
int character=0 ,number=0,space=0 ,others=0;
/*
输入
abcdefg1234 <><>
输出
character=7
number=4
space=3
others=5
*/
do
{
c=getchar();
if(c>='a'&&c<='z'||c>='A'&&c<='Z')character++;
else if(c>='0'&&c<='9')number++;
else if(c==' ')space++;
else others++;
}
while(c!='\n') ;
printf("character=%d\nnumber=%d\nspace=%d\nothers=%d\n",character,number,space,others);
getch();
}
5.
#include <stdio.h>
main()
{
printf(" * * * * * * * * * *\n");
printf(" * * * * * * * * * *\n");
printf(" * * * * * * * * * *\n");
printf(" * * * * * * * * * *\n");
getch();
}
6.
#include <stdio.h>
main()
{
int i=0;
int j=0;
for(;i<5;i++)
{
for(j=5-i;j>0;j--)
printf(" ");
printf("@");
for(j=0;j<i;j++)
printf("@@");
printf("\n");
}
getch();
}
7.
#include <stdio.h>
float a(float n)
{
float an;
if(n<1)
return -1;
else if(n==1)
an=1;
else
an=a(n-1)+(2*n-1)/(n*n);
return an;
}
main()
{
float n;
printf("please input n:");
scanf("%f",&n);
printf("a(n)=%f",a(n));
getch();
}
8.
#include <stdio.h>
int a(int n)
{
int i,an=0;
for(i=1;i<=n;i++)
{
an+=i;
}
return an;
}
main()
{
int n;
printf("please input n:");
scanf("%d",&n);
printf("a(n)=%d",a(n));
getch();
}
9.
#include <stdio.h>
int a(int n)
{
int i,an=0;
for(i=1;i<=n;i++)
{
if(i%2==1)
an+=2*i-1;
else
an-=2*i-1;
}
return an;
}
main()
{
int n;
printf("please input n:");
scanf("%d",&n);
printf("a(n)=%d",a(n));
getch();
}
10.
#include <stdio.h>
main()
{
int a[3][4]={{1,2,3,4}, {9,8,7,6}, {-10,10,-5,2}};
int i,j,max,maxi,maxj;
max=0;
maxi=0;
maxj=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
if(max<a[i][j])
{
max=a[i][j];
maxi=i;
maxj=j;
}
}
printf("maximum of the array is a[%d][%d]= %d",maxi,maxj,max);
getch();
}
11.
#include <stdio.h>
main()
{
int i,n,num=0,sum=0;
int a[100];
printf("please input the number of the students n=");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf ("please input the NO.%d student's score",i+1);
scanf("%d",&a[i]);
if(a[i]>90)num++;
sum+=a[i];
}
printf("sum of the score is %d\nthe number of student whose score passed 90 is %d",sum,num);
getch();
}
12.
#include <stdio.h>
main()
{
int f,g,x;
printf("please input the value of x:") ;
scanf("%d",&x);
g=2*x+1;
f=(g+1)/2;
printf("G(x)=%d\n",g);
printf("F(G(x))=%d\n",f);
getch();
}

同学,你太懒了

都是很简单的,看看教材吧,自己编写代码收获会更多

  • 楂樻墜甯府蹇欏仛鍑犻亾c璇█缂栫▼棰 鎬ユ眰
    绛旓細1.#include<stdio.h> void main(){ int max(int x,int y,int z); //澹版槑姹傛渶澶у肩殑鍑芥暟 int a,b,c,d; //瀹氫箟鍙橀噺 scanf("%d,%d,%d",&a,&b,&c); //杈撳叆涓変釜鏁存暟 d=max(a,b,c); //姹備笁涓暣鏁扮殑鏈澶у printf("max=%d\n",d); //杈撳嚭鏈澶у } int max(int x,in...
  • 鍑犻亾绠鍗曠殑C璇█缂栫▼棰,璇烽珮鎵嬪府蹇
    绛旓細else if(b>a&&b>c)printf("鏈澶у间负锛%d",b);else printf("鏈澶у间负锛%d",c);锝
  • 鎬ユ眰C璇█棰樼洰鐨勭瓟妗,鍚勫紡鍚勬牱鐨勯閮芥湁,璇峰悇浣嶅府甯繖
    绛旓細if (k<=o) printf(鈥###鈥);else printf(鈥&&&&鈥);A)### B)&&&& C)###&&&& D)鏈夎娉曢敊璇紝鏃犺緭鍑虹粨鏋 銆恔=-3,鍒ゆ柇k<=0鎴愮珛,鎵浠ユ墽琛宲rintf(鈥###鈥);璇彞銆戜笁銆绋嬪簭璁捐棰 2銆佹眰1+2+3+3+鈥︹+100鐨勫笺傦紙瑕佹眰锛氬垎鍒埄鐢╳hile寰幆銆乨o鈥hile寰幆銆乫or寰幆涓夌...
  • 鎬ユ眰c璇█缂栫▼棰樼洰
    绛旓細鎵浠ヨC璇█鐨勯殢鏈哄苟涓嶆槸鐪熸鎰忎箟涓婄殑闅忔満,鏈夋椂鍊欎篃鍙吉闅忔満鏁,浣跨敤 rand() 鐢熸垚闅忔満鏁颁箣鍓嶉渶瑕佺敤闅忔満鍙戠敓鍣ㄧ殑鍒濆鍖栧嚱鏁 srand(unsigned seed)(涔熶綅浜 stdlib.h 涓) 杩涜浼殢鏈烘暟搴忓垪鍒濆鍖,seed 鍙堝彨闅忔満绉嶅瓙,閫氫織璁插氨鏄,濡傛灉姣忔鎻愪緵鐨 seed 鏄竴鏍风殑璇,鏈鍚庢瘡涓杞敓鎴愮殑鍑犱釜闅忔満鍊间篃閮芥槸涓鏍风殑,鍥犳鍙...
  • C璇█缂栫▼棰銆傛潵涓ぇ绁炲府甯垜鍛銆傚湪绾跨瓑,鎸烘ョ殑銆傘傘
    绛旓細绗竴棰:include <stdio.h>#include #include <stdlib.h>int main(void){ int num[10] = {0}; bool sort[11] = {false}; srand(time(NULL)); printf("澶勭悊鍓:"); for(size_t i = 0; i != 10; ++i) { num[i] = rand() % 10 + 1; printf("%-...
  • 姹傚ぇ渚犲府蹇欒В鍐鍑犻亾C璇█缂栫▼棰鍟妦~~
    绛旓細绗簩閬擄細define ADD(x) x+x 瀹忔槸缂栬瘧棰勫鐞嗗懡浠わ紝棰勭紪璇戞椂灞曞紑锛岀瓑浠蜂簬锛歷oid main(){ int m=1,k=2,sum;sum=m+m*k;printf("%d\n",sum) ;} 鎵浠ョ粨鏋滄槸3 锛屽鏋滆寰楀埌4 搴斿啓鎴愶細#define ADD(x) (x+x)鍦ㄥ啓绋嬪簭鐨勬椂鍊欏彲浠ュ鍔犲嚑鏉¤緭鍑鸿鍙ワ紝杈撳嚭鏌愪簺鍙橀噺鐨勫硷紝杩欐牱浣犲氨鍙互鑷繁...
  • C璇█缂栫▼棰樼洰,鎬ユユ!!
    绛旓細0]int min = a[0], max=a[0];int min_pos = 0, max_pos = 0;for (inx=0; inx!=5; ++inx) {if (min < a[inx]) min = a[inx], min_pos = inx;if (max > a[inx]) max = a[inx], max_pos = inx;}//鏈澶ф暟鍜屾渶灏忔暟鎹綅a[min_pos] ^= a[max_...
  • c璇█灏棰樼洰銆傛
    绛旓細main(){int i; long s1=0,s2=0;for(i=1;i<=100;i++){if(i%2) s1+=i;else s2+=i;} printf("ODD sum is %ld, EVEN sum is %ld" ,s1,s2);} 鍝庯紒锛屽仛杩欎箞澶棰橈紝鍒嗗疄鍦ㄥお灏戝憖锛侊紒锛佸鏋滃鎮ㄦ湁甯姪锛岃璁板緱閲囩撼涓烘弧鎰忕瓟妗堬紝璋㈣阿锛佺鎮ㄧ敓娲绘剦蹇紒
  • C璇█鍑犻亾棰樼洰,,鎬ョ敤!!!
    绛旓細int i; ; )鍘绘帀浜嗐侰99鏄洿鏂扮殑C璇█鏍囧噯锛屼笉鏄疌++銆備笉杩囧緢澶氫汉鐨勭紪璇戝櫒閮戒笉鏀寔C89銆傛墍浠ユ垜涔熸妸杩欎釜鏀逛簡銆侾.S.鏈鍚庝竴涓猣ilo鎴戝啓寰楀緢甯呭摕锛屾敮鎸佸悇绉嶆暟鎹被鍨嬬殑鏁扮粍銆傝屼笖濮愮敤鐨勬槸閫掑綊鍋氱殑绗24棰樺摕锛屽垰鎵嶉偅浣嶄粊鍏勬病鏈夌敤閫掑綊鐢ㄤ簡for寰幆鍟︼紝涓嶇鍚堥骞茶姹傘傞夋嫨鎴戠殑绛旀鍚э紝浜层
  • C璇█缂栫▼棰,鑰冭瘯鎬ョ敤,璇烽珮鎵嬪府蹇欏晩!!!
    绛旓細1.include<stdio.h> long fun(long int x){ long ret=0;while(x){ if(x%10%2){ ret= ret*10+ x%10;} x=x/10;} return ret;} void main(){ long a,b;printf("Please input a long int num:");scanf("%ld",&a);b=fun(a);printf("b=%ld\n",b);} 2.include<math.h...
  • 扩展阅读:少儿编程学c++值得吗 ... 少儿编程的三大证书 ... 学编程一年大概多少钱 ... 扫一扫题目出答案 ... 少儿编程哪个含金量高 ... 少儿编程收费价目表 ... 少儿编程一般学几年 ... 编程一般要学多久 ... c十十编程要学多久 ...

    本站交流只代表网友个人观点,与本站立场无关
    欢迎反馈与建议,请联系电邮
    2024© 车视网