羅湖c語言編程,c語言編程求兩數之和

本文目錄一覽:

c語言是編程嗎?

C語言是編程的一種語言。。

簡單的說,編程就是為了藉助於計算機來達到某一目的或解決某個問題,而使用某種程序設計語言編寫程序代碼,並最終得到結果的過程。

簡單編程!!急需!!c語言!

1、求1+2+3+……….+100。(循環)

答案

#includestdio.h

void main()

{

int i,sum=0;

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

sum=sum+i;

printf(“%d”,sum);

}

2、 求1*2*3*……….*10。(循環)

答案

void main()

{

int i=0,j=1;

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

{

j*=i;

}

printf(“%d”,j);

return 0;

}

3、 輸入三個數字,輸出他們的最大值。(if)

答案

#includestdio.h

void main()

{int a,b,c,d;

scanf(“%d,%d,%d”,a,b,c);

d=max(a,b,c);

printf(“max=%d”,d);

getch();/*暫停看運行結果*/

}

int max(int x,int y,int z)

{int u;

if(x=yx=z)

u=x;

else if(y=xy=z)

u=y;

else

u=z;

return(u);

4.用起泡法對十個數據排序(數組實現)

答案

#includestdio.h

main ( )

{  int i,j,t;

static int a[10]={5,7,4,2,3,6,1,0,9,8};

for(j=0;j9;j++)

{   for(i=0;i9-j;i++)

{  if(aa)

{ t=a;a=a;a=t ;

}

}

}

for(i=0;i10;i++)

printf(“%2d”,a);

}

5、輸入十個數字,逆序輸出。(數組實現)

答案

#includestdio.h

main()

{int a[10],i=0;

for(i=0;i=9;i++)

scanf(“%f”,a);

printf(“\n”);

for(i=9;i=0;i–)

printf(“%f”,a);

}

6輸入兩個數,交換他們的值並輸出。(元素交換)

答案

#includestdio.h

int main ()

{

int m,n,temp;

scanf(“%d%d”,m,n);

if (mn)

{

temp=m;

m=n;

n=temp;

}

printf(“%d”,m);

return 0;

}

7.輸出9*9乘法表。(雙層循環)

答案

#include stdio.h

void main()

{

int i=1;

for(i; i=9; i++)

{

int j=1;

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

{

printf(“%d*%d=%d “, i, j, i*j);

}

printf(“\n”);

}

}

8.輸入一行字元,將所有的小寫字母轉換成大寫字母,大寫字母轉換成小寫字母,其餘字元不變。輸出轉變後的這行字元。

答案

#include “stdio.h”

void main()

{

char a[n];

int i;

scanf(“%s”,a);

printf(“大寫為:”);

for(i=0;i=n;i++)

{

if(a=’z’a=’a’)

a=a-32;

printf(“%c”,a);

}

printf(“\n小寫為:”);

for(i=0;i=3;i++)

{

a=a+32;

printf(“%c”,a);

}

}

9、 編寫一個簡單計算器程序,要求能夠完成兩個數的+,-,*,/四種運算。輸出運算式及運算結果。(switch)

6.2

#include”stdio.h”

main()

{char c;int i=0,j=0,k=0,l=0;

while((c=getchar())!=』\n』)

{if(c=65c=90||c=97c=122) i++;

else if(c=48c=57) j++;

else if(c==32) k++;

else l++;}

printf(“i=%d,j=%d,k=%d,l=%d\n”,i,j,k,l);

}

6.6

#include”math.h”

main()

{int x=100,a,b,c;

while(x=100×1000) {a=0.01*x;b=10*(0.01*x-a);c=x-100*a-10*b;

if(x==(pow(a,3)+pow(b,3)+pow(c,3))) printf(“%5d”,x);x++;}

}

6.7

main()

{int m,i,j,s;

for(m=6;m10000;m++)

{s=1;

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

if(m%i==0) s=s+i;

if(m-s==0)

{printf(“%5d its fastors are 1 “,m);for(j=2;jm;j++) if(m%j==0)

printf(“%d “,j);printf(“\n”);}

}

}

main()

{int m,i,j,s;

for(m=6;m1000;m++)

{s=m-1;

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

if(m%i==0) s=s-i;

if(s==0)

{printf(“%5d its fastors are 1 “,m);for(j=2;jm;j++) if(m%j==0)

printf(“%d “,j);printf(“\n”);}

}

}

6.8

main()

{int i=1,n;double t,x=1,y=2,s,sum=0;

scanf(“%ld”,n);

while(i=n) {s=y/x;sum=sum+s;t=y;y=y+x;x=t;i++;}

printf(“%f\n”,sum);

}

11,

#includestdio.h

void main()

{

char c;

while((c=getchar())!=’\n’)

{

c=c+4;

if(c’Z’+4||c’z’)

c=c-26;

}

printf(“%c”,c);

}

printf(“\n”);

}

12,P111  5.5  5.6(switch)

5.5

#include stdio.h

main()

{int x,y;

printf(“輸入x:”);

scanf(“%d”,x);

if(x1)

{ y=x;

printf(“x=%3d, y=x=%d\n”,x,y);

}

else if (x10)

{ y=2*x-1;

printf(“x=%3d, y=2*x-1=%d\n”,x,y);

}

else

{ y=3*x-11;

printf(“x=%3d, y=3*x-11=%d\n”,x,y);

}

}

5.6

#include stdio.h

main()

{ float score;

char grade;

case 2:

printf(“請輸入學生成績:”);

scanf(“%f”,score);

while(score100||(score0)

{ printf(“\n輸入有誤,請重新輸入:”);

scanf(“%f”,score);

}

switch((int)(score/10))

{ case 10:

case 9: grade=』A』;break;

case 8: grade=』B』;break;

case 7: grade=』C』;break;

case 6: grade=』D』;break;

case 5:

case 4:

case 3:

case 1:

case 0: grade=』E』;

}

printf(“成績是%5.1f,相應的等級是%c。\n”,score,grade);

}

13(一元二次方程求根)    (求閏年)

5.5

#includestdio.h

void main()

{

int year,leap;

scanf(“%d”,year);

if(year%4==0)

{

if(year%100==0)

{

if(year%400==0)

leap=1;

else

leap=0;

}

else

leap=1;

}

else

leap=0;

if(leap)

printf(“%d is”,year);

Else

printf(“%d is not”,year);

printf(“a leap year.\n”)

}

5.6

14.

2.17

輸出50個學生中成績高於80分者的學號和成績

2.18

輸出2000——2500年每一年是否閏年

#includestdio.h

void main()

{

int year;

year=2000;

go: if(((year%4 == 0)(year%100 != 0)) || (year%400 == 0))

printf(“%d is run nian”,year);

if(year=2500)

year=year++;

if(year2500)

goto end;

goto go;

end:   getch();

}

c語言:編程

#include “stdio.h”

#include “string.h”

int main()

{

 char str[100]={0};

 char max;

 int i,len,pos;

 printf(“輸入一個字元串:”);

 gets(str);

 len=strlen(str);

 max=str[0];

 pos=0;

 for(i=1;ilen;i++) //找最大字元位置

  if(str[i]max)

  {

   max=str[i];

   pos=i;

}

 for(i=pos;i0;i–)//移位

  str[i]=str[i-1];

 str[0]=max;//最大字元放在首位

 puts(str);

}

求大神幫忙做一道C語言簡單編程,要求如下

#includestdio.h

int main()

{

char c = ‘Y’;

float x,y,z;

char operate;

while(c==’Y’ || c==’y’)

{

printf(“please enter number1:”);

scanf(“%f”,x);

printf(“please enter operate:”);

getchar();

scanf(“%c”,operate);

printf(“please enter number2:”);

scanf(“%f”,y);

switch(operate)

{

case ‘+’:

z = x+y;

printf(“%f + %f = %f\n”,x,y,z);

break;

case ‘-‘:

z = x-y;

printf(“%f – %f = %f\n”,x,y,z);

break;

case ‘*’:

z = x*y;

printf(“%f * %f = %f\n”,x,y,z);

break;

case ‘/’:

z = x/y;

printf(“%f / %f = %f\n”,x,y,z);

break;

}

printf(“Do you want to continue(Y/N or y/n):”);

getchar();

scanf(“%c”,c);

}

return 0;

}

編程c語言,求大神幫忙,要詳細過程

#include “stdio.h”

int main(void){

    double faHeight,moHeight,t;

    char sex;

    while(1){

        printf(“Enter the height of your father and mother(cm)…\n”);

        if(scanf(“%lf%lf”,faHeight,moHeight)  faHeight50  moHeight50)

            break;

        printf(“Error, input again: “);

    }

    while(1){

        printf(“Enter your gender(m or f)…\n”);

        if(scanf(” %c”,sex)  sex==’m’ || sex==’f’)

            break;

        printf(“Error, can only enter f or m: “);

    }

    t=faHeight+moHeight;

    printf(“\nYour father is %.0f cm tall.\n”,faHeight);

    printf(“Your mother is %.0f cm tall.\n”,moHeight);

    printf(“Expect your height is %.0f cm.\n”,sex==’m’ ? t*0.54 : t/2);

    return 0;

}

C語言的簡單編程問題,希望大哥大姐指點,萬分感謝

一、計算機中的整數是用補碼來表示的 (補碼是什麼?請查詢相關資料)

二、C中的整型常量默認為int類型,int類型是一個有符號類型(有符號類型和無符號類型請查詢相關資料)

三、char類型數據在計算機中佔一個位元組,int類型佔4個位元組,char類型是一個有符號類型

四、197在計算機中存放的二進位碼為:0000….. 11000101(int類型佔4個位元組,11000101前面有3*8=24個0)

同樣198在計算機中存放的二進位碼為:0000….. 11000110

五、 c1=197; c2=198;這兩個賦值後,c1=11000101 c2=11000110 ,不同類型的數據在賦值時(大類型賦值給小類型),系統會自動截斷高位,將低有效位賦值給小類型的變數

六、現在來看為什麼輸出是:printf(“c1=%d,c2=%d\n”,c1,c2); =》c1=-59,c2=-58

按%d來輸出一個char變數,就是將變數的數值輸出出來。

c1中存儲的是 11000101,按有符號數解釋就是-59 ,即:11000101是-59的補碼

c2中存儲的是 11000110,按有符號數解釋就是-58 ,即:11000110是-58的補碼

七、printf(“c1=%c,c2=%c\n”,c1,c2); =》c1=?c2=?

按%c來輸出char變數,就是將變數所代表的字元輸出出來

由於197(-59) 198(-58)不是一個有效的字元(ASCII),因些只能以?來代替。

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/182927.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-11-24 16:25
下一篇 2024-11-24 16:25

相關推薦

  • AES加密解密演算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密演算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES演算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演著非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • Python語言由荷蘭人為中心的全能編程開發工程師

    Python語言是一種高級語言,很多編程開發工程師都喜歡使用Python語言進行開發。Python語言的創始人是荷蘭人Guido van Rossum,他在1989年聖誕節期間開始…

    編程 2025-04-28
  • Python語言設計基礎第2版PDF

    Python語言設計基礎第2版PDF是一本介紹Python編程語言的經典教材。本篇文章將從多個方面對該教材進行詳細的闡述和介紹。 一、基礎知識 本教材中介紹了Python編程語言的…

    編程 2025-04-28
  • Python語言實現人名最多數統計

    本文將從幾個方面詳細介紹Python語言實現人名最多數統計的方法和應用。 一、Python實現人名最多數統計的基礎 1、首先,我們需要了解Python語言的一些基礎知識,如列表、字…

    編程 2025-04-28
  • Python作為中心語言,在編程中取代C語言的優勢和挑戰

    Python一直以其簡單易懂的語法和高效的編碼環境而著名。然而,它最近的發展趨勢表明Python的使用範圍已經從腳本語言擴展到了從Web應用到機器學習等廣泛的開發領域。與此同時,C…

    編程 2025-04-28
  • Python基礎語言

    Python作為一種高級編程語言擁有簡潔優雅的語法。在本文中,我們將從多個方面探究Python基礎語言的特點以及使用技巧。 一、數據類型 Python基礎數據類型包括整數、浮點數、…

    編程 2025-04-28

發表回復

登錄後才能評論