大學程式實驗.C語言.函數入門.簡單函數的構造
- 0 目錄
- 1 函數入門
- 2.1 簡單函數的構造
- 2.1.1 題目
- 2.1.2 源碼
- 2.1.3 下載下傳
- 2 下一章
0 目錄
1 函數入門
2.1 簡單函數的構造
2.1.1 題目
構造主函數,要求使用scanf和printf語句以及條件判斷進行輸出,具體要求如下:
如果x小于1,y=x;如果x>=1&&x<10,則y=2x-1;否則3x-11;
2.1.2 源碼
// c1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
void main()
{
int x;
int y;
//
scanf("%d",&x);
//
if (x<1)
{
y=x;
}
else if (x>=1&&x<10)
{
y=2*x-1;
}
else
y=3*x-11;
//
printf("%d\n",y);
}