(用c++输入输出语句)编程序。输入一个3位的正整数,输出其各位上的数字。

作者&投稿:化琪 (若有异议请与网页底部的电邮联系)
用c++输入输出语句编程序。输入一个4位的正整数,输出其各位上的数字。~

[cpp] view plain copy
/*
* 文件名称:Ex1-1
* 作 者: 陶浩然
* 完成日期: 2016 年 3月 10 日
* 版 本 号:v1.0
* 对任务及求解方法的描述部分:
* 输入描述:ab
* 问题描述:求ab的和与差
* 程序输出: ab的和与差
* 问题分析: 略
* 算法设计:a-b&a+b
*/
#include
using namespace std;
int main( )
{
int a,b,sum,min;
cin>>a>>b;//输入两个整数,两个数之间用空格分开
sum=a+b;
min=a-b;

cout<<"a+b="<<sum<<endl;
cout<<"a-b="<<min<<endl;
return 0;

}

#include using namespace std ;int main(){ int n; int unit,tens,hund; cin >> n ; unit = n%10 ; tens= n/10%10; hund=n/100; if ( hund < tens ) { int temp=hund;hund=tens;tens=temp; } if ( hund < unit ) { int temp=hund;hund=unit;unit=temp; } if ( tens < unit ) { int temp=tens;tens=unit;unit=temp; } cout << hund*100+tens*10+unit <<endl; return 0;}

C++程序:

#include <iostream>

using namespace std;

int main()
{
int num;
int a, b, c;

printf("请输入一个三位数:");
cin>>num;

a = num / 100;
b = num / 10 % 10;
c = num % 10;

cout<<"三位数字分别是:"<<a<<" "<<b<<" "<<c<<endl;

return 0;
}


运行测试:

请输入一个三位数:123
三位数字分别是:1 2 3


void main(){
int num,a,b,c;
printf("请输入已个三位正整数:\n");
scanf("%d",&num);
a=num/100;
b=(num%100)/10;
c=num%10;
printf("百位:%d,十位:%d,个位:%d",a,b,c);

}




C语言中输入输出语句转换成C++语句
c语言中的输入输出语句换成C++语句是将printf()函数换成cout对象,将scanf()函数换成cin对象。问题中提及的代码:printf("第%d名的名字:",t);scanf("%s",&p->date.ach[t-1].name);对应的C++代码:cout<<"第"<<t<<"名的名字:";cin>>p->date.ach[t-1].name;...

在c++中,如果我想实现输入1,输出一段文字,输入2,输出另一段文字,输入3...
可以用switch语句 switch(a)\/\/a为输入的文字 { case 1:cout<<"wen zi1 "<<endl;break;case 2:cout<<"wen zi2 "<<endl;break;case 3:cout<<"wen zi3 "<<endl;break;case 4:cout<<"wen zi4 "<<endl;break;\/\/下面可以在加case } 此段代码外在家一个for循环就可以循环执行 ...

用C++编写一个程序。输入一行字符。输出其中的英文字母 数字字符和其 ...
{ digit++;}else if(s[i]>='a' && s[i] <= 'z'){ alpha++;}else if(s[i]>='A' && s[i] <= 'Z'){ alpha_cap++;}else{ misc++;} } printf("There are %d digits, %d alphabets(%d capitalized), %d othercharaters\\n",digit,alpha+alpha_cap,alpha_cap, misc);} ...

c++中字符输入格式中,分隔符是什么
则正确的输出语句是D。逗号 表示puts(a),puts(b);是逗号表达式语句,从左到右依次执行。输出结果与分号隔开成的2个语句一样:char a[80]="aaa",b[80]="bbb";puts(a),puts(b); \/\/逗号。字符串主要用于:编程,概念说明、函数解释、用法详述见正文,这里补充一点:字符串在存储上类似字符...

描述 输入一个ASCII码,输出对应的字符。 C++代码
include <stdio.h>int main(){int ch;scanf("%d", &ch);printf("%c\\n", (char)ch);return 0;} include <iostream>using namespace std;int main(){int ch;cin >> ch;cout << (char)ch << endl;return 0;}

2、 编写一个简单的C++程序:通过键盘输入你的基本信息,如姓名、学号...
include <iostream> using namespace std;int main(){ long number;char name[50];int class_;cout << "请依次输入学号、姓名、班级(例子:000007 张三 3),以空格分隔:\\n";cin >> number >> name >> class_;cout << "姓名:" << name << endl << "学号:" << number << endl...

c++字符数组怎么整体输入输出
c++字符数组可以用以下的方法输入不含空格和TAB的字符串,以回车结束:char s[300];cin>>s;或:scanf("%s",s);可以用以下的方法输入可以包含空格和TAB的字符串,以回车结束:gets(s);可以用以下的方法整体输出一个字符串:printf("%s\\n",s);或:cout>>s>>endl;或:puts(s);

C语言中有输出格式控制,C++怎么实现?
对于流数据的输入输出格式,C++提供了两种不同的控制方式,一种是使用ios_base类提供的setf、width等函数设置输入输出格式,另一种是通过重载的格式控制符“<<”、“>>”以及流格式控制对象进行设置。本文只介绍:用函数设置或者恢复格式 大部分流的输入输出格式可以用setf函数来设置。该函数有两种重载形式...

用c++写连续输入‘a’~‘z’若干个字母,如果输入‘z’,“退出”程序...
} while (true); \/\/ 始终循环直到输入'z'cout << "已退出程序!" << endl;return 0;} ```上述代码使用do-while循环结构不断获取用户输入,并根据输入的字符进行相应的处理。如果输入的是'a'~'z'之间的小写字母,将其输出;如果输入的是'z',则使用break语句跳出循环;其他情况下输出提示...

c++输入一行字符,输出其中的字母的个数例如输入“Et2f5F218”输出结果为...
include<stdio.h>int isLetter(char c){if(c>='A'&&c<='Z')return 1;if(c>='a'&&c<='z')return 1;return 0;}char s[999],i,k;int main(){scanf("%s",s);for(i=0;s[i];i++){switch(isLetter(s[i])){case 1:{k++;break;}case 0:{break;}default:{break;}}}...

西市区19757433420: 用C++编程:从键盘上输入若干学生的成绩,统计并输出最高成绩和最低成绩,当输入负数时结束输入. -
曾备吉姆: #include<iostream> using namespace std; int main() { double a[100]; double max=0,min=100,t; int i; for(i=0;i<100;i++) { cin>>a[i]; if(a[i]<0) break; else { if(a[i]>max) max=a[i]; if(a[i]<min) min=a[i]; } } cout<<"最大值是:"<<max<<endl; cout<<"最小...

西市区19757433420: 如何用C++编一个输出一句话的程序? -
曾备吉姆: #includeint main(){ cout<<" "<

西市区19757433420: 用C++编写程序输入十个数输出最大和最小的数 -
曾备吉姆: main() {double input,max,min;cin>>input;max = min = input;for( int i = 0;i < 9; i++ ){cin>>input;if(max < input){max = input;}if(min > input){min = input;}}cout< cout<} 很久没有写C++了,也没有经过验证是不是正确的,要包含什么头文件我也忘记了.里面要是写错了别怪我哈.思路应该是正确的

西市区19757433420: 用C++编程,实现字符串的输入输出,具体要求如下 -
曾备吉姆: #include using std::cin; using std::cout; using std::string; using std::endl; int main() { const unsigned int NUM = 10; //字符串数量 string strArray[NUM]; string str; for(unsigned int i = 0;i < NUM; ++i) { cout << "Please input string " << i << ":" << ...

西市区19757433420: C++ 输入输出语句实现输出两个整数的和 写个程序 谢谢 -
曾备吉姆: 定义两个变量,键盘输入赋值给两个变量,输出变量的和. //参考代码 #include <iostream> #include<string.h> using namespace std; int main() {int a,b;//定义两个整型变量cin>>a>>b;//输入两个变量并赋值cout<<a+b; //输出两个变量的和return 0; } /*运行结果: 12 65 77 */

西市区19757433420: 在C++中,编写一个程序,关于文件与数据输入输出的,具体如下: -
曾备吉姆: 这是我写的,希望能给您带来帮助:#include<iostream>#include<fstream>#include<string> using namespace std; int main() { char str[256]; cin.get(str,256,'\n'); fstream f("a1.txt",ios::out); if(!f) { cout<<"fail!"; return 1; } f<<str; f.close(); f.open("...

西市区19757433420: 怎么在C++上写一段简单输出程序(使用上If语句)? -
曾备吉姆: 展开全部#include using std::cout; using std::endl; void main() { int i=1; cout<return; } //编辑框中居然不支持使用cout输出字符串,BS一下

西市区19757433420: C++语言编程:输入三个数,从小到大输出. -
曾备吉姆: #include "stdio.h"#include "conio.h" main() { int x,y,z,t; scanf("%d%d%d",&x,&y,&z); if (x>y) {t=x;x=y;y=t;} /*交换x,y的值*/ if(x>z) {t=z;z=x;x=t;} /*交换x,z的值*/ if(y>z) {t=y;y=z;z=t;} /*交换z,y的值*/ printf("small to big: %d %d %d\n",x,y,z); ...

西市区19757433420: 怎样用c++设计一个程序 输入1,输出红 输入2, 输出橙 以此类推 -
曾备吉姆: 这个题实际上就是考察switch...case语句的用法. #include <iostream> using namespace std; void mian() {int choice = 0;cout<<"请输入:";cin>>choice;switch(choice){case 1: cout<<"红"; break;case 2: cout<<"橙"; break;case 3: cout<<"黄"; break;case 4: cout<<"绿"; break;//后面的依次类推...default: cout<<"您的输入有误!"<<endl;} }

西市区19757433420: 用C++编写一个函数,实现将输入的字符串逆序输出,字符串的输入和输出在main函数种实现. -
曾备吉姆: #include "stdio.h" #include "string.h" main() {char ch[100];int i;printf("请输入一个字符串:\n");gets(ch);for(i=strlen(ch)-1;i>=0;i--){putchar(ch[i]);}printf("\n"); }

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网