#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);
}
}
void jrs(char chars[],int l)
{
int i;
printf(“Result: “);
for(i=0;i<l;i++)
{
printf(“%c”,chars);
}
for(i=l-1;i>=0;i–)
{
printf(“%c”,chars);
}
}
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,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=chars[l-1]+1;l++;
}
for(i=a;i<l;i++)
{
printf(“%c”,chars);
}
}
void ftav(char chars[],int l)
{
int s=0; int i;
printf(“Result: “);
for(i=0;i<l;i++)
{
s=s+(int)chars;
}
for(i=0;i<l-1;i++)
{
printf(“%d+”,chars);
}
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.
>> 本文固定链接: http://www.vcgood.com/archives/1108