#include <stdio.h>
void rs(char chars[],int l);
void jrs(char chars[],int l);
void irs(char chars[],int l);
void es(char chars[],int l);
void ftav(char chars[],int l);
main()
{
char c[100]; int n;int len=0; clrscr();
printf("Enter Original String: ");
gets(c);
while(c[len]|=0) len++;
printf("\n1)\tReverse String\n");
printf("\n2)\tJoin Reverse String\n");
printf("\n3)\tInsert Reverse String\n");
printf("\n4)\tEncrypt String\n");
printf("\n5)\tFind Total ASCII Value\n\n");
printf("\nEnter Choice:");
scanf("%d",&n);
switch(n)
{
case 1: rs(c,len); break;
case 2: jrs(c,len); break;
case 3: irs(c,len); break;
case 4: es(c,len); break;
case 5: ftav(c,len); break;
default: printf("Your choice is invalid.");
}
getch();
return 0;
}
void rs(char chars[],int l)
{
int i=0;
printf("Result: ");
for(i=l-1;i>=0;i--)
{
printf("%c",chars[i]);
}
}
void jrs(char chars[],int l)
{
int i;
printf("Result: ");
for(i=0;i<l;i++)
{
printf("%c",chars[i]);
}
for(i=l-1;i>=0;i--)
{
printf("%c",chars[i]);
}
}
void irs(char chars[],int l)
{
int i;int j;
printf("Result: ");
for(i=0,j=l-1;i<l,j>=0;i++,j--)
{
printf("%c%c",chars[i],chars[j]);
}
}
void es(char chars[],int l)
{
int i; int a;a=l;
printf("\nEnter Number: ");
scanf("%d",&i);
printf("Result: ");
for(i;i>0;i--)
{
chars[l]=chars[l-1]+1;l++;
}
for(i=a;i<l;i++)
{
printf("%c",chars[i]);
}
}
void ftav(char chars[],int l)
{
int s=0; int i;
printf("Result: ");
for(i=0;i<l;i++)
{
s=s+(int)chars[i];
}
for(i=0;i<l-1;i++)
{
printf("%d+",chars[i]);
}
printf("%d=",chars[l-1]);
printf("%d",s);
}
显示结果:
Result:
Enter Original String:ABC
1) Reverse String
2) Join Reverse String
3) Insert Reverse String
4) Encrypt String
5) Find Total ASCII Value
Enter Choice:1
Result: CBA
Enter Choice:2
Result: ABCCBA
Enter Choice:3
Result: ACBBCA
Enter Choice:4
Enter Number: 3
Result: DEF
Enter Choice:5
Result: 65+66+67=198
Enter Choice:6
Your choice is invalid.
QQ:29734175
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |