用c语言编写一个程序,从键盘上输入两个字符给字符变量a,b,并输出变量a,b的值。 编写一个程序,通过指针变量将一个字符数组中的字符倒序输出
\u7f16\u5199C\u8bed\u8a00\u7a0b\u5e8f\uff1a\u4ece\u952e\u76d8\u4e0a\u8f93\u5165\u4e24\u4e2a\u6574\u578b\u6570\u636e,\u5206\u522b\u5b58\u653e\u5728\u6574\u578b\u53d8\u91cfa \u548cb \u4e2d, \u7136\u540e\u8f93\u51fa\u8868\u8fbe\u5f0fa/b \u548c a%b \u7684\u503c.#include
int main()
{
int a,b;
scanf("%d %d", &a,&b );
printf("%d/%d=%d\n", a,b,a/b );
printf("%d%%%d=%d\n", a,b,a%b );
return 0;
}
\u4f60\u72af\u4e86\u4e24\u4e2a\u9519\u8bef.
1.b\u7684\u751f\u547d\u5468\u671f\u53ea\u662foutput\u51fd\u6570,\u5f53\u8fd0\u884c\u5230printf\u7684\u65f6\u5019,b\u7684\u5185\u5b58\u5df2\u7ecf\u88ab\u7cfb\u7edf\u56de\u6536\u4e86,\u6240\u4ee5p\u6307\u5411\u5730\u7684\u4e00\u5757\u65e0\u6548\u7684\u5185\u5b58.
2.b\u5e94\u8be5\u88ab\u521d\u59cb\u5316.\u7533\u8bf7b\u7684\u65f6\u5019,\u5b83\u91cc\u9762\u7684\u5185\u5bb9\u4e0d\u786e\u5b9a,\u800cprintf\u4f1a\u9010\u4e2a\u8f93\u51fa\u5b57\u7b26\u76f4\u5230\u9047\u5230\u7ed3\u675f\u7b26'\0'.
\u6211\u4fee\u6539\u540e\u662f\u8fd9\u6837\u7684.
#include "stdio.h"
#include "string.h"
char *output(char name[]);
main()
{
char name[20];
scanf("%s",name);
printf("%s\n",output(name));
}
char *output(char name[])
{
int i,n;
char *p;
char *b = new char[20];//\u628ab\u7684\u5185\u5b58\u653e\u5230\u5806\u4e0a\u53bb,\u5b83\u7684\u751f\u547d\u5468\u671f\u5c31\u5168\u5c40\u4e86.
memset(b, 0, 20);//\u521d\u59cb\u5316.
n=strlen(name);
for(i=0;i<n;i++)
b[i]=name[n-1-i];
p=b;
return p;
}
#include <stdio.h> //编译预处理命令
int main(int argc, char *argv[]) //主函数,字符的声明
{
char a,b; //定义字符a,b
scanf("%c %c",&a,&b); //输入字符a,b
printf("%c %c\n",a,b);//打印字符a,b
return 0; //返回并且输出a,b
}
扩展知识:
Matlab变量的特点:不需事先声明,也不需指定变量类型,Matlab自动根据所赋予变量的值或对变量所进行的操作来确定变量的类型;在赋值过程中,如果变量已经存在,Matlab会用新值代替旧值,并以新的变量类型代替旧的变量类型。
变量的默认类型为double。
#include <stdio.h>
int main()
{
char a,b;
a=getchar();
scanf("%c", &b );
printf("a=%c\n", a );
printf("b=%c\n", b );
return 0;
}
#include <stdio.h>
int main()
{
int i;
double d ;
char c;
printf("input char :" );
c=getchar();
putchar(c);
printf("input integer :" );
scanf("%d", &i );
printf("i=%10d\n", i );
printf("input float:" );
scanf("%lf", &d );
printf("d=%.2lf\n", d );
return 0;
}
1、
#include <stdio.h>
int main(int argc, char *argv[])
{
char a,b;
scanf("%c %c",&a,&b);
printf("%c %c\n",a,b);
return 0;
}
2、
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int a;
double b;
char c;
scanf("%d %lf",&a,&b);
getchar();
c=getchar();
printf("%10d %.2lf\n",a,b);
putchar(c);
return 0;
}
绛旓細鏈汉涔熸槸瀛C璇█鐨勶紝浠ヤ笅鐨绋嬪簭鏄寜鐓т綘鐨勮姹缂栧啓鐨勶細#include <stdio.h> //姹傝緭鍏ユ暟鍚勪綅鏁扮殑绔嬫柟鍜 void main(){ int x,sum=0,j;printf("璇疯緭鍏涓涓姝f暣鏁帮細");scanf("%d",&x); //杈撳叆涓涓暟 while(x!=0) //鍒ゆ柇X鏄惁涓洪浂 { j=x%10; //鍙栦釜浣嶆暟瀛 sum+=j*j*...
绛旓細1銆侀鍏堬紝闅忎究鍒涘缓涓涓湁main鏂规硶鐨勭被銆2銆佸畾涔変竴涓瓧绗︿覆鍙橀噺锛岃繖閲岀粰鍙橀噺璧嬪硷紝鍓嶅悗閮界暀鏈変竴涓绌烘牸銆3銆佸厛杩愯涓閬嶏紝鐪嬭緭鍑烘晥鏋滐紝鍙互鐪嬪埌鐧惧害鍖呮嫭绌烘牸鐨勫嚑涓瓧绗﹂兘鎵撳嵃鍑烘潵浜嗐4銆佷负浜嗘洿鍔犳竻鏅帮紝鐢ㄥ瓧绗︿覆瀵硅薄鍙﹀涓涓柟娉曗渓ength()鈥濆緱鍒版瀛楃涓茬殑闀垮害涓6锛 璇存槑鐨勭‘鏄滅櫨搴︹濆姞涓や釜绌烘牸鐨勯暱搴...
绛旓細include <stdio.h> int main(){ int n;scanf("%d", &n);if(n > 0) printf("姝f暟");else if(n < 0) printf("璐熸暟");else{printf("闆");} return 0;}
绛旓細浣犲ソ锛佷互涓嬫槸涓涓狢璇█绋嬪簭锛屼娇鐢do-while寰幆璇彞浠庨敭鐩浠绘剰杈撳叆n涓疄鏁帮紝骞惰绠楀嚭鍏朵腑鐨勬渶澶у煎拰鏈灏忓硷細include <stdio.h> int main() { int n, i = 0;float num, max, min;printf("璇疯緭鍏ヨ杈撳叆鐨勫疄鏁颁釜鏁皀: ");scanf("%d", &n);do { printf("璇疯緭鍏ュ疄鏁: ");scanf("%f", ...
绛旓細1.include <stdio.h> include <string.h> int main(void){ int nNum1,nNum2;printf("璇疯緭鍏ョ涓涓鏁存暟锛");scanf("%d",&nNum1);printf("\n璇疯緭鍏ョ浜屼釜鏁存暟锛歕n");scanf("%d",&nNum2);printf("\n杈撳叆鐨勪袱涓暟涓猴細%d,%d,鍏跺ぇ灏忓叧绯讳负锛",nNum1,nNum2)if(nNum1 < nNum2)...
绛旓細鎬濊矾锛氬畾涔涓涓鍑芥暟int fun(int a[])锛岃鍑芥暟閫氳繃浼犻掔殑鍙傛暟鏁扮粍渚濇閬嶅巻锛屽鎵炬渶澶у硷紝鏈鍚庤繑鍥炴渶澶у硷紝涓诲嚱鏁拌緭鍏ユ暟缁勶紝璋冪敤璇ュ嚱鏁拌緭鍑烘渶澶у笺傚弬鑰冧唬鐮侊細include<stdio.h>#define n 10int fun(int a[]){//姹傛暟缁刟鐨勬渶澶у煎嚱鏁癷nt i,max=a[0];for(i=1;i<n;i++)if(max<a[i]) ...
绛旓細鍙互鍙傝冧笅闈㈢殑浠g爜锛歩nclude <stdio.h> void main(){ char ch;scanf("%c",&ch);if(ch>='A'&&ch<='Z'){ ch=ch+32;printf("%c\n\n",ch);}else{ printf("%c\n\n",ch);} }
绛旓細include <stdio.h>int main(){ int array[10]; int max = 0, min = 0; for(int i = 0; i < 10; i ++) { scanf("%d", &array[i]); if (i == 0) { max = array[i]; min = array[i]; } else if (array[i] > max) max = array[i]...
绛旓細NO_WARNINGS//VS鐜涓嬮渶瑕侊紝VC涓嶉渶瑕 include<stdio.h> void main(){ char a;//瀹氫箟涓涓瀛楃 printf("璇疯緭鍏ヤ竴涓瓧绗︼細");//鏂囧瓧鎻愮ず scanf("%c", &a);//杈撳叆涓涓瓧绗 printf("鍏跺悗缁瓧绗︿负锛");//鏂囧瓧鎻愮ず printf("%c\n", a + 1);//杈撳嚭鍏朵箣鍚庣殑瀛楃 } 绋嬪簭杩愯缁撴灉濡備笅锛...
绛旓細涓嬮潰鏄竴浜C缂栫▼棰樼洰锛1. 缂栧啓绋嬪簭锛屼粠閿洏杈撳叆涓や釜鏁存暟锛岃緭鍑哄畠浠殑鍜屻佸樊銆佺Н銆佸晢銆佷綑鏁般2. 缂栧啓绋嬪簭锛屼粠閿洏杈撳叆涓夎褰㈢殑涓夋潯杈归暱锛屽垽鏂畠浠槸鍚﹀彲浠ユ瀯鎴愪笁瑙掑舰锛屽苟杈撳嚭涓夎褰㈢殑绫诲瀷锛堢瓑杈广佺瓑鑵般佷竴鑸級銆3. 缂栧啓绋嬪簭锛屼粠閿洏杈撳叆瀛楃涓诧紝缁熻鍏朵腑鐨勫ぇ鍐欏瓧姣嶃佸皬鍐欏瓧姣嶃佹暟瀛楀拰鍏朵粬瀛楃鐨勪釜鏁帮紝骞...