c語言if else語句_查找C程序的輸出(如果為else語句)| 設置1

c語言if else語句

Find the output of the following programs,

查找以下程序的輸出,

Program 1)

程序1)

#include <stdio.h>
int main()
{
int x = 400, y, z;
if (x >= 500)
y = 400;
z = 300;
printf("%d %d\n", y, z);
return 0;
}

Output

輸出量

32766 300

Explanation:

說明:

In the code, the condition x>=500 is false, so the variable y will not be assigned and the statement z=300 is written after the conditional statement, so it will be assigned with 300. Thus, the value of y will be a garbage value and value of z will be 300.

在代碼中,條件x> = 500為假,因此將不分配變量y,并且在條件語句之后寫入語句z = 300 ,因此將其分配為300。因此, y的值將為垃圾值和z的值為300。

Program 2)

程序2)

#include <stdio.h>
int main()
{
int p = 800, q, r;
if (p >= 700)
q = 600;
r = 500;
printf("%d %d\n", q, r);
return 0;
}

Output

輸出量

600 500

Explanation:

說明:

In the code, the condition p>=700 is true, so the variable q will be assigned with the value 600 and the statement r=500 is written after the conditional statement, so it will be assigned with 500. Thus, the value of q will be a 600 value and value of r will be 500.

在代碼中,條件p> = 700為true,因此將為變量q分配值600,并在條件語句后寫入語句r = 500 ,因此將其分配為500。因此, q將是600的值,而r的值將是500。

Program 3)

程序3)

#include <stdio.h>
int main()
{
int a = 30, b = 40;
if (a == b);
printf("%d %d\n", a, b);
return 0;
}

Output

輸出量

30 40

Explanation:

說明:

In the code, the condition if(a==b); is terminated with semicolon so the statement printf("%d %d\n",a,b); will not be consider as a body of the if statement. Thus, the program will print the value of a and b.

在代碼中,條件為if(a == b); 以分號終止,因此語句printf(“%d%d \ n”,a,b); 不會被視為if語句的主體。 因此,程序將打印a和b的值。

Program 4)

程序4)

#include <stdio.h>
int main()
{
int e = 4;
float f = 4.0;
if (e == f) {
printf("E and F are equal\n");
}
else {
printf("E and F are not equal");
}
return 0;
}

Output

輸出量

E and F are equal

Explanation:

說明:

In the code, variable e is an integer type and variable f is a float type, while comparing them with an if statement (if(e==f)), the value of f will be truncated to an integer (due to implicit type conversion). Thus, the condition will be true and "E and F are equal" will be printed.

在代碼中,變量e是整數類型,變量f是浮點類型,將它們與if語句( if(e == f) )進行比較時, f的值將被截斷為整數(由于隱式類型)轉換)。 因此,條件為真, 并且將打印“ E和F相等”

Program 5)

程序5)

#include <stdio.h>
int main()
{
int p = 4, q, r;
q = p = 15;
r = p < 15;
printf("p = %d q = %d r = %d\n", p, q, r);
return 0;
}

Output

輸出量

p = 15 q = 15 r = 0

Explanation:

說明:

In the code, the statement q = p = 15; is assigning 15 to the variables p and q and the statement r = p<15; is assigning 0 to the variable r because p is not less than 15 (condition is false). Thus, the value of p, q and r will be 15, 15, and 0.

在代碼中,語句q = p = 15; 將變量p和q賦值為15,并且語句r = p <15; 因為p不小于15(條件為假),所以將0賦給變量r 。 因此, p , q和r的值將分別為15、15和0。

Program 6)

計劃6)

#include <stdio.h>
int main()
{
int i = 65;
char j = 'A';
if (i == j) {
printf("This place is beautiful\n");
}
else {
printf("This place is not beautiful\n");
}
return 0;
}

Output

輸出量

This place is beautiful

Explanation:

說明:

The character variable stores the ASCII code of the given character (it's also a number type of variable). Thus, the value of j will be 65 (The ASCII Code of 'A' is 65). So the condition if(i==j) will be true and "This place is beautiful" will be printed.

字符變量存儲給定字符的ASCII碼(它也是變量的數字類型)。 因此, j的值為65(“ A”的ASCII碼為65)。 因此條件if(i == j)將為true,并且將打印“這個地方很漂亮”

Program 7)

計劃7)

#include <stdio.h>
int main()
{
float p = 13.25, q = 14.5;
if (p = q) {
printf("Hello\n");
}
return 0;
}

Output

輸出量

Hello

Explanation:

說明:

In the statement if(p=q), p=q is not a comparison operation, we used = (assignment operator), thus the value of q will be assigned into p and the statement will be evaluated to 14.5 which is a non-zero value and conditional will be true.

在語句if(p = q) , p = q不是比較運算的情況下,我們使用= (賦值運算符),因此q的值將分配給p,并且該語句的計算結果為14.5 ,這不是零值和條件將為真。

Recommended posts

推薦的帖子

  • Find output of C programs (if else statement) | set 2

    查找C程序的輸出(如果為else語句)| 設置2

  • Find output of C programs (Bitwise Operators) | Set 1

    查找C程序的輸出(按位運算符)| 套裝1

  • Find output of C programs (Bitwise Operators) | Set 2

    查找C程序的輸出(按位運算符)| 套裝2

  • Find output of C programs (Strings) | Set 1

    查找C程序的輸出(字符串)| 套裝1

  • Find output of C programs (Strings) | Set 2

    查找C程序的輸出(字符串)| 套裝2

  • Find output of C programs (Structures) | Set 1

    查找C程序的輸出(結構)| 套裝1

  • Find output of C programs (Mixed topics) | Set 1

    查找C程序的輸出(混合主題)| 套裝1

  • Find output of C programs (Mixed topics) | Set 2

    查找C程序的輸出(混合主題)| 套裝2

  • Find output of C programs (Mixed topics) | Set 3

    查找C程序的輸出(混合主題)| 套裝3

  • Find output of C programs (Character) | Set 1

    查找C程序的輸出(字符)| 套裝1

  • Find output of C programs (floating point) | Set 1

    查找C程序的輸出(浮點數)| 套裝1

  • Find output of C programs (For loops) | Set 1

    查找C程序的輸出(用于循環)| 套裝1

  • Find output of C programs (Arrays) | Set 1

    查找C程序的輸出(數組) 套裝1

翻譯自: https://www.includehelp.com/c/if-else-find-output-of-programs-c-set-1.aspx

c語言if else語句

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541635.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541635.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541635.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Javascript模塊化編程(二):AMD規范

這個系列的第一部分介紹了Javascript模塊的基本寫法&#xff0c;今天介紹如何規范地使用模塊。 七、模塊的規范 先想一想&#xff0c;為什么模塊很重要&#xff1f; 因為有了模塊&#xff0c;我們就可以更方便地使用別人的代碼&#xff0c;想要什么功能&#xff0c;就加載什么模…

html側滑菜單mui,mui側滑菜單點擊含有mui-action-menu類的控件無法實現側滑

.mui-action-menu標題欄 菜單按鈕 指定href"#id"顯示與隱藏側滑菜單html:側滑菜單列表側滑菜單列表2側滑菜單列表3標題具體內容href:https://badfl.gitbooks.io/mui/content/mui-action-menu.htmlAndroid 使用代碼主動去調用控件的點擊事件(模擬人手去觸摸控件)使用代…

hanlp 訓練模型_LTP 4.0!單模型完成6項自然語言處理任務

來源|哈工大SCIR語言技術平臺&#xff08;Language Technology Platform, LTP&#xff09;是哈工大社會計算與信息檢索研究中心&#xff08;HIT-SCIR&#xff09;歷時多年研發的一整套高效、高精度的中文自然語言處理開源基礎技術平臺。該平臺集詞法分析&#xff08;分詞、詞性…

typescript 學習

typescript將在不久的將來從前端大一統的趨勢中脫穎而出成為主流編譯器。學習ts對前端開發人員來說是不可或缺的。同時&#xff0c;也要抓緊學習es2015/6/7。ts和es6并不是對立的。而是相輔相成的。ts的競爭和打擊對象實質上是babel…… 官方資料 # 官方地址&#xff1a; https…

計算機中央處理器cpu_中央處理器(CPU)| 計算機科學組織

計算機中央處理器cpu中央處理器(CPU) (Central Processing Unit (CPU)) The CPU is the brain of the computer system. It works as an administrator of a system. CPU是計算機系統的大腦。 它以系統管理員的身份工作。 All the operations within the system are supervised…

計算機應用基礎專2020春,計算機應用基礎(專)(專,2020春)(20200831130023).pdf

計算機應用基礎(專)(專&#xff0c; 2020 春)使用 " 格式刷”按鈕&#xff0c;可以進行 ___________操作。選擇一項&#xff1a;a. 復制文本的格式b. 刪除文本c. 復制文本d. 保持文本你的回答正確正確答案是&#xff1a;復制文本的格式在 Word 的文檔中插入復雜的數學公式…

computed set 自定義參數_深入理解vmodel之自定義組件用法

根據上一篇《深入理解 v-model 之表單用法》基本對 v-model 有了比較深的理解&#xff0c;接下來我們看看它如何在自定義組件中使用。首先&#xff0c;我們知道下面兩個用法等價的&#xff1a;<input v-model"msg" /><input :value"msg" input&qu…

01json轉字符串

/** * json轉字符串聲明 */ (NSString *)jsonToString:(NSDictionary *)dic; /** * json轉字符串實現 */ (NSString *)jsonToString:(NSDictionary *)dic { if(!dic){ return nil; } NSData *jsonData [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWriting…

AYUSH的完整形式是什么?

AYUSH&#xff1a;阿育吠陀&#xff0c;瑜伽和自然療法&#xff0c;烏納尼&#xff0c;悉達多和順勢療法 (AYUSH: Ayurvedic, Yoga and Naturopathy, Unani, Siddha and Homeopathy) AYUSH is an abbreviation of Ayurvedic, Yoga and Naturopathy, Unani, Siddha, and Homeopa…

大班科學電子計算機,計算器教案

計算器的認識和簡單應用教學內容&#xff1a;義務教育六年制小學第九冊第二單元第42頁。教學目標&#xff1a;1、通過學生自主探究&#xff0c;掌握計算器的使用方法&#xff0c;并能夠用計算器進行簡單的計算。2、借助計算器解決生活中的數學問題、探索數學規律&#xff0c;體…

arraylist能否接收強轉類型_ArrayList 源碼解析

點擊上方"IT牧場"&#xff0c;選擇"設為星標"技術干貨每日送達&#xff01;前言 JDK源碼解析系列文章&#xff0c;都是基于JDK8分析的&#xff0c;雖然JDK14已經出來&#xff0c;但是JDK8我還不會&#xff0c;我…類圖 實現了RandomAccess接口&#xff0c;…

exit c+_C / C ++中的exit(0)vs exit(1)與示例

exit cexit() is a library function in C/C programming language, it is used to terminate the calling process (function) immediately i.e. we can say it is used for the normal program termination and also perform the several cleanup steps. exit()是C / C 編程語…

校園計算機網絡系統,校園計算機網絡系統

一、校園網的基本概念基本功能&#xff1a;數據交換、資源共享&#xff0c;這里所指的數據包括各種信息&#xff0c;基本組成和結構&#xff1a;基本網絡由網絡網絡的分類&#xff1a;有多種分類方法&#xff0c;按規模可分為局域網、區域網、&127;廣域網。局域網服務范圍一…

mc有什么紅石機器人_我的世界10月考試!來測測你的MC成績吧~

考試規則&#xff1a;本次考試為閉卷考試&#xff0c;考生需要在30分鐘內完成試卷。試卷總分為100分&#xff0c;其中包括單項選擇題50分&#xff0c;多項選擇題20分&#xff0c;判斷題30分。考試內容包括《我的世界》手游1.11.0及以上版本在不添加任何模組的情況下的所有游戲內…

130、 Android OkHttp完全解析(轉載)

完全解析&#xff1a;http://blog.csdn.net/lmj623565791/article/details/47911083 從原理角度解析http文件上傳 http://blog.csdn.net/lmj623565791/article/details/23781773 https://github.com/hongyangAndroid/okhttputils

json轉string示例_C.示例中的String.Copy()方法

json轉string示例C&#xff03;String.Copy()方法 (C# String.Copy() Method) String.Copy() method is used to copy a string to new string object, it returns a new instance of String with the same value as given string. String.Copy()方法用于將字符串復制到新的字符…

自定義分頁 html,MVC 自定義HtmlHelper幫助類型之分頁

方法一&#xff1a;在項目中增加App_Code文件夾&#xff0c;新增一個MyHtmlper.cshtml視圖文件寫入代碼&#xff1a;helper Pagger(int pageIndex, int pageCount){for (int i 1; i < pageCount; i){if (i ! pageIndex){(i)}else{i}}}新增一個HomeControllerpublic class H…

vue 對象繼承_Vue2.0中組件的繼承與擴展是什么

Vue2.0中組件的繼承與擴展是什么發布時間&#xff1a;2020-12-07 14:04:09來源&#xff1a;億速云閱讀&#xff1a;100作者&#xff1a;小新小編給大家分享一下Vue2.0中組件的繼承與擴展是什么&#xff0c;相信大部分人都還不怎么了解&#xff0c;因此分享這篇文章給大家參考一…

stack示例_C.示例中的Stack.Clone()方法

stack示例C&#xff03;Stack.Clone()方法 (C# Stack.Clone() method) Stack.Clone() method is used to create a shallow copy of the stack. Stack.Clone()方法用于創建堆棧的淺表副本。 Syntax: 句法&#xff1a; Object Stack.Clone();Parameters: None 參數&#xff1a…

簡述計算機圖形的圖形應用主要有哪些,5計算機圖形學考試簡答題復習.doc

5計算機圖形學考試簡答題復習計算機圖形學考試簡答題復習1、簡述計算機動畫的概念&#xff0c;它經歷了哪幾個階段的發展&#xff1f;(2分)計算機動畫是指采用圖形與圖像的處理技術&#xff0c;借助于編程或動畫制作軟件生成一系列的景物畫面&#xff0c;其中當前幀是前一幀的部…