讓字串中的數字相加
#include <stdio.h>
#include <stdlib.h>
int main() {
char a[20];
int i,k,x,m[20],p=0;
printf("enter the word that include number\n");
gets(a);
for(i=0;a[i];i++)
if(sscanf(a+i,"%d%n",&k,&x)){
m[i]=k;
p=p+m[i];
i+=x;
}
printf("\n");
printf("%d ",p);
return 0;
}
*******************************
讓英文字母開頭變大寫
#include <stdio.h>
#include <stdlib.h>
int main() {
char a[30];
int i,k,x,m[20],p=0;
printf("enter the word\n");
gets(a);
if( a[0]>='A' && a[0]<='Z')
{
a[0]=a[0];
}
else
if( a[0]>='a' && a[0]<='z')
{
a[0]=a[0]-32;
}
for(i=0;i<=30;i++){
if(a[i]==46){
if( a[i+1]>='A' && a[i+1]<='Z')
{
a[i+1]=a[i+1];
}
else
if( a[i+1]>='a' && a[i+1]<='z')
{
a[i+1]=a[i+1]-32;
}
}
}
printf("%s",a);
return 0;
}
沒有留言:
張貼留言