C语言题目 12位整数相加相减的运算(用上数组)

来源:百度知道 编辑:UC知道 时间:2024/05/24 05:02:38

定义long型变量,用到ascii码,具体怎么编再想想,不要怕烦,相信你一定行!^-^

/*这是实现加法的答案,可以随便多少位,减法的可以自己去弄*/
/* 本程序在本机测试通过,环境:Turbo C for Windows 集成实验与学习环境 */
#include "stdio.h"
#include "string.h"
#include "ctype.h"
char s1[100];
char s2[100];
char s3[100];

main()
{
int i,j,k,h;/*i代表s1的要加的字符,j代表S2要加的字符,k用来计量加法的进位数*/
int tag1,tag2;/*用来判断输入的字符是否合法*/
int len1,len2,len3;/*用来计量各个字符数组的长度*/
char x;/*用来临时存放相加之后的字符*/
k=0;
tag1=0;
tag2=0;
/*判断输入是否合法*/
do
{
tag1=0;
tag2=0;
printf("Please Input the Numbers:\nLike this:\n\t123456\n");
scanf("%s",s1);
printf("Please Input the Other Numbers:\n");
scanf("%s",s2);
for(h=0;h<strlen(s1);h++)
if(isdigit(s1[h])==0)tag1=1;
if(tag1)printf("This Number one is not digits,Please Input it again.\n");