當前位置:首頁 » 編程語言 » c語言用指針判斷a至z
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言用指針判斷a至z

發布時間: 2022-10-21 06:15:17

c語言,如何判斷一個字元數組中元素是否包含除字母(a-z,A-Z)和數字(0-9)以外的東西。

可以的,利用循環。
下面只判斷是不是全為字母或數字,如果不是則列印其位置和符號。
/* Note:Your choice is C IDE */
#include "stdio.h"
void main()
{

int i,c=0;
char a[6];
scanf("%s",&a);
for(i=0; i<5 ;i++)
{
if(a[i] <= 'z'&&a[i] >='a'||a[i] <= 'Z' && a[i] >='A'||a[i]>=48 && a[i]<=57)
{
c++;
}
else
printf("第%d個位置:%c\n",i+1,a[i]);

}

if(c==5)
{
printf("全為字母或數字\n");
}

}
不懂的地方可以追問

⑵ 利用C語言指針比較三個數並且從小到大輸出

#include<stdio.h>

int main()

{

int a,b,c,*p1,*p2,*p3,*t;

p1=&a;

p2=&b;

p3=&c;

printf("請輸入三個整數:");

scanf("%d%d%d",p1,p2,p3);

if(*p1>*p2){t=p1;p1=p2;p2=t;}

if(*p1>*p3){t=p1;p1=p3;p3=t;}

if(*p2>*p3){t=p2;p2=p3;p3=t;}

printf("%d %d %d ",*p1,*p2,*p3);

getch();

return 0;

}

⑶ c語言指針

#include<stdio.h>

int swap(char *sentence)
{ char *ph,*pt,c;
int n=0;
ph=pt=sentence; //ph指向第1個字元
while ( *pt ) pt++; pt--; //pt指向最後1個字元
while ( ph<pt )
{
while ( ((*ph)<'A' || (*ph)>'Z') && ph<pt ) ph++; //ph向後移動到大寫字母直到超過pt位置為止
while ( ((*pt)<'A' || (*pt)>'Z') && ph<pt ) pt--; //pt向前移動到大寫字母直到超過ph位置為止

if ( ph<pt ) { c=(*ph); (*ph)=(*pt); (*pt)=c; ph++; pt--; n++; } //如果沒有互相超過位置,交換
else break; //pt位置和ph位置發生交錯,結束
}
printf("%s ",sentence);
return n;
}
void main()
{ char str[256]={"I Don't Like You."};
int n;
printf("%s ",str);
n=swap(str);
printf("%d ",n);
}

⑷ C語言輸出A~Z

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void main ( )
{

int x,y;
int row=6,col=6;
int r,c;
r=0;
for (y=0;y<col;y++)
{
c=65+r;
for (x=0;x<col-y;x++)
{
printf("%c",(char)c);
c+=x+2+y;
}
r+=y+1;
printf("\n");
}
system("pause");
}

⑸ c語言中a到z,遞增如何表示

如果a和z都是整數
for(i=0;i<(z-a);i++)
{
a++
printf("%d",a)
}
如果是字母
char a='a',z='z';int c,i;
c='z'-'a'
for(i=0;i<c;i++)
printf("%c",a+i)

⑹ c語言 用指針 來判斷N個數里最大直 最小直

#include<stdio.h>
void main()
{
int a[100];int i,n;int *max; int *min:
printf("輸入你想輸入數的個數\n");
scanf("%d",&n);
printf("輸入你想輸入的值\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
max=a;
min=a;
for(i=1;i<n;i++)
{
if(*max<a[i])
max=&a[i];
if(*min>a[i])
min=&a[i];
}
printf("最大數為%d\n最小數為%d\n",*maz,*min);
}

⑺ 在c語言中怎樣將a轉化成z

如果是字元處理的話,『a』的ASCII碼是97 ,『z』的ASCII碼是122;要將『a』轉化為『z』 只需 讓『a『+25

⑻ c語言中怎麼用指針調換順序

要調換三個數的順序,用排列組合原理簡單的計算總共有6種方法,不知道樓主是想按其中某種方法交換變數的具體數值,還是將所有6種排序都列印出來?
例如,a=1,b=2,c=3,交換後結果為:a=3,b=1,c=2.
首先需要兩個中間變數作為交換的媒介。程序如下

main()
{
int
a=1,b=2,c=3;
int
*x=a,*y=b,*z=c;/*定義3個指針變數,並分別賦予初值為a,b,c的地址。*/
int
*p=null,*s=null;/*x為交換中介指針變數,初始化為空*/
*p=*x;
*s=*y;
*x=*z;
*y=*p;
*z=*s;
printf("%d
%d
%d",a,b,c);
getch();
}
其實交換數不需要用到指針,直接運用變數本身也可交換。當然指針交換的好處在於函數內部可以實際交換兩個數的值。

⑼ c語言如何用指針判斷一個字元串中哪些為整數

include<stdio.h>
#include<ctype.h>
int i; //在C語言程序中,不能在其它變數聲明前有可執行語句,所以 int i; i=0; int a;是錯誤的,
//而全局變數如果不賦值就自動初始化為0,如果想賦值,也需int i=0;
int a;
char *str;
char string[80];//必須指明數組的大小
void s( )// 此處不需要參數,因為前面已經定義了全局變數字元數組string
{
printf("please enter the element of the string");
gets(string);
}
void is_integer()//該函數也不需要參數,原因同上一個函數
{
char *str;
str= &string[i];
while(*str !='\0')
{
str= &string[i];
a=isdigit ( *str );
if( a != 0 )//isdigit的結論是或不是數字,而沒有進行轉換,所以判斷後,還要以%c格式輸出
printf("%c 是數字\n",*str);
i++;
}
}
void main (void)
{
s();
is_integer( );//函數調用時,實參處不能加類型說明,如is_integer(char *str);是錯誤的,
//如果有參數也只能是is_integer(*str);
}

⑽ 編寫一段C語言程序,用來輸出從a~z,A~Z這些字母分 別對應哪些數字,另外他還想知道,這些數字

int i;
for(i='a';i〈='z';i十十)
printf("%c=%d\n",i,i);
大寫字母類似。