Some examples c language

Some examples array

1. integers n input from the keyboard, all indices statistics and odd number of array elements is an even number.
#include <stdio.h>

int main ()
{
int A [10] = {};
int NUM = 0;
int I = 0;
for (I = 0; I <=. 9; I ++)
{
Scanf ( "% D", & A [I]) ;
}
for (I = 0; I <=. 9; I ++)
{
IF (I% 2 = 0!)
Continue;
IF (A [I]% 2 == 0)
NUM ++;
the printf ( "NUM:% D \ n- ", NUM);
the printf (" I:% DA [I]: D% \ n-", I, a [I]);
}
return 0;
}
2. character array for converting alphabetical letters two after the letter position, if a 'z' or 'Z', respectively, becomes 'b' or 'B', the same non-alphabetic characters. I.e., 'a' → 'c' ' b' → 'd'

``*#include<stdio.h>
int main()
{
	int i=0;
	char arr[8]={'a','B','R','d','y',2,'Z',4};
	for(;i<8;i++)
	{
		if(arr[i]<='z'&&arr[i]>='a'||arr[i]>='A'&&arr[i]<='Z')
		{
			if(arr[i]=='z')
			{``
				``arr[i]='b';
			printf("%c\n",arr[i]);
				continue;
			}
			if(arr[i]=='y')
			{
				arr[i]='a';
		printf("%c\n",arr[i]);
				continue;
			}
			if(arr[i]=='Y')
			{``
				arr[i]='A';
			printf("%c\n",arr[i]);
				continue;
			}
			if(arr[i]=='Z')
			{
				arr[i]='B';
			printf("%c\n",arr[i]);
				continue;
			}
			arr[i]+=2;
			printf("%c\n",arr[i]);
		
		}
	}*
	return 0;
}*
  1. N is an arbitrary integer determined whether the palindrome. (Palindrome correct reading verlan are the same number, such as: 2112,121, etc.)
#include <stdio.h>
#include <string.h>
int main()
{
	int n=0;
	int flag=0;
	int num = 0;
	printf("press one number please!\n");
	scanf("%d",&n);
	int a[100];
	int i=0;
	while(n)
	{
		num++;
		a[i]=n%10;
		n/=10;
		printf("a[%d]=%d\n",i,a[i]);
		i++;
	}
	for(int b=0;b<num/2;b++)
	{
		if(a[0+b]==a[num-b-1])
			flag++;
	}
	printf("flag:%d\n",flag);
	if(flag==(num/2))
		printf("这是回文数");

	printf("num:%d\n",num);
	
	return 0;

}

4. integer input from the keyboard 10, an integer of 5 to check whether the data contained in these, and if so, to find out which is the first of several inputted.

#include<stdio.h>

int main()
{
	int i=0;
	int a[10];
	int num=0;
	int num5[10];
	printf("请输入十个数\n");
	for(;i<10;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==5)
		{
			num5[num]=i;
			num++;
		}
	}
	for(i=0;i<num;i++)
	{
		printf("下标%d\n",num5[i]);
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_42614008/article/details/95322657