11. Array
--------------------------------------------------------------------
(1)
#include<stdio.h>
int a[5]={11,22,33,44,55},*p=a,i;
void main()
{
for(i=0;a[i];i++)
{
printf("%d ",*(p+i));
}
}
--------------------------------------------------------------------
(2)
#include<stdio.h>
int a[5]={11,55,88,22,44},i,j;
int *p=&a;
void main()
{
for(i=4;i>=0;i--)
{
for(j=0;j<i;j++)
{
if(a[j]<a[j+1])
{
a[j]=a[j]^a[j+1];
a[j+1]=a[j]^a[j+1];
a[j]=a[j]^a[j+1];
}
}
}
for(i=0;i<5;i++)
{
printf("%d ",*(p+i));
}
}
--------------------------------------------------------------------
(3)
#include<stdio.h>
int a[7]={5,3,1,2,1,9,6},i,j;
void main()
{
for(i=3;i>=0;i--)
{
for(j=0;j<i;j++)
{
if(a[j]<a[j+1])
{
a[j]=a[j]^a[j+1];
a[j+1]=a[j]^a[j+1];
a[j]=a[j]^a[j+1];
}
}
}
for(i=0;i<7;i++)
{
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(4)
#include<stdio.h>
int a[5]={10,20,30,40,50},i,ele,add=0;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
add=add+a[i];
}
printf("Sum of all arrays : %d\n",add);
}
--------------------------------------------------------------------
(5)
#include<stdio.h>
int a[5]={123,23,89,3425,721},i,ele,add=0,r,num;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(r=0,num=a[i];num;num=num/10)
{
r=num%10;
}
add=add+r;
}
printf("Sum of all arrays : %d\n",add);
}
--------------------------------------------------------------------
(6)
#include<stdio.h>
int a[6]={12,234,321,45,654,1234},i,ele,add=0,r,num,newnum;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(r=0,num=a[i],newnum=0;num;num=num/10)
{
r=num%10;
if(num<9)
break;
newnum=newnum*10+r;
}
a[i]=newnum;
for(r=0,num=a[i],newnum=0;num;num=num/10)
{
r=num%10;
newnum=newnum*10+r;
}
a[i]=newnum;
}
for(i=0;i<ele;i++)
{
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(7)
#include<stdio.h>
int a[5]={10,100,1000,100,10},i,j,ele,pos;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
printf("Binary of a[%d] = ",a[i]);
for(pos=31;pos>=0;pos--)
{
printf("%d",(a[i]>>pos)&1);
}
printf("\n");
}
}
--------------------------------------------------------------------
(8)
#include<stdio.h>
unsigned int a[5]={12,10,35,63,512};
int i,ele;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
a[i]=a[i]>>1;
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(9)
#include<stdio.h>
unsigned int a[5]={10,15,64,100,511};
int i,ele,pos,set=0,clear=0;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(pos=31;pos>=0;pos--)
{
if(a[i]>>pos&1)
set++;
else
clear++;
}
}
printf(" set bits = %d\n clear bits = %d",set,clear);
}
--------------------------------------------------------------------
(10)
#include<stdio.h>
unsigned int a[5]={10,15,64,100,511},b[5];
int i,ele,pos,set=0;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(set=0,pos=31;pos>=0;pos--)
{
if(a[i]>>pos&1)
set++;
}
printf("%d ",b[i]=set);
}
}
--------------------------------------------------------------------
(11)
#include<stdio.h>
int a[10]={-11,11,12,-12,9,8,-3,10,22};
int i,ele,positive=0,negative=0,odd=0,even=0;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
if(a[i]>>31&1)
{
negative++;
goto l1;
}
else
{
positive++;
}
if(a[i]%2==0)
even++;
else
odd++;
l1:;
}
printf("Negative = %d\nPositive = %d\nOdd = %d\nEven = %d\n ",negative,positive,odd,even);
}
--------------------------------------------------------------------
(12)
#include<stdio.h>
int a[6]={2,2,3,5,5,4};
int i,ele,s=0;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(s=a[0],i=1;i<ele;i++)
{
if(a[i]<s)
s=a[i];
}
printf("%d",s);
}
--------------------------------------------------------------------
(13)
#include<stdio.h>
int a[7]={2,2,3,5,5,4,4};
int i,ele,l=0,sl=0;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
if(a[0]==a[1])
{
a[1]=a[1]^a[2];
a[2]=a[1]^a[2];
a[1]=a[1]^a[2];
}
if(a[0]>a[1])
{
l=a[0];
sl=a[1];
}
else if(a[1]>a[0])
{
l=a[1];
sl=a[0];
}
for(i=2;i<ele;i++)
{
if(a[i]>l)
{
sl=l;
l=a[i];
}
else if(a[i]>sl && a[i]!=l)
{
sl=a[i];
}
}
printf("Second largest = %d",sl);
}
--------------------------------------------------------------------
(14)
#include<stdio.h>
int a[7]={2,2,1,5,5,4,4};
int i,ele,s1=0,s2=0;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
if(a[0]==a[1])
{
a[1]=a[1]^a[2];
a[2]=a[1]^a[2];
a[1]=a[1]^a[2];
}
if(a[0]<a[1])
{
s1=a[0];
s2=a[1];
}
else if(a[1]<a[0])
{
s1=a[1];
s2=a[0];
}
for(i=2;i<ele;i++)
{
if(a[i]<s1)
{
s2=s1;
s1=a[i];
}
else if(a[i]<s2 && a[i]!=s1)
{
s2=a[i];
}
}
printf("Smalest = %d\n",s1);
printf("Second smalest = %d",s2);
}
--------------------------------------------------------------------
(15)
#include<stdio.h>
int a[6]={11,22,33,44,55,66},ele,i;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
a[3]=a[3]^a[4];
a[4]=a[3]^a[4];
a[3]=a[3]^a[4];
for(i=0;i<ele;i++)
{
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(16)
#include<stdio.h>
int a[6]={111,222,333,444,555,666},*p,*q,ele,i;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
p=&a[0];
q=&a[ele-1];
*p=*p^*q;
*q=*p^*q;
*p=*p^*q;
for(i=0;i<ele;i++)
printf("%d ",a[i]);
}
--------------------------------------------------------------------
(17)
#include<stdio.h>
int a[7]={11,33,22,2,9,1,6},i,j;
void main()
{
for(i=2;i>=0;i--)
{
for(j=0;j<i;j++)
{
if(a[j]>a[j+1])
{
a[j]=a[j]^a[j+1];
a[j+1]=a[j]^a[j+1];
a[j]=a[j]^a[j+1];
}
}
}
for(i=0;i<7;i++)
{
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(18)
#include<stdio.h>
int a[7]={2,3,5,7,11,13},in=0,num=99,ele,i;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=ele-1;i!=in;i--)
{
a[i]=a[i-1];
}
a[in]=num;
for(i=0;i<ele;i++)
printf("%d ",a[i]);
}
--------------------------------------------------------------------
(19)
#include<stdio.h>
int a[7]={2,3,5,7,11,13},in=3,num=51,ele,i;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=ele-1;i!=in;i--)
{
a[i]=a[i-1];
}
a[in]=num;
for(i=0;i<ele;i++)
printf("%d ",a[i]);
}
--------------------------------------------------------------------
(20)
#include<stdio.h>
int a[7]={2,3,5,7,11,13},sr,num=10,ele,i,cdiff=0,diff=0,len;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(len=0;a[len];len++);
for(i=len-1;i>0;i--)
{
diff=a[i]-a[i-1];
if(diff>cdiff)
{
sr=i;
cdiff=diff;
}
diff=0;
}
for(i=ele-1;i!=sr;i--)
{
a[i]=a[i-1];
}
a[sr]=num;
for(i=0;i<ele;i++)
printf("%d ",a[i]);
}
--------------------------------------------------------------------
(21)
#include<stdio.h>
int a[9]={30,11,45,34,14,8,50},in,num,ele,i;
void main()
{
while(1)
{
printf("Enter number : ");
scanf("%d",&num);
printf("Enter index : ");
scanf("%d",&in);
ele=sizeof(a)/sizeof(a[0]);
for(i=ele-1;i!=in;i--)
{
a[i]=a[i-1];
}
a[in]=num;
for(i=0;i<ele;i++)
printf("%d ",a[i]);
printf("\n");
}
}
--------------------------------------------------------------------
(22)
#include<stdio.h>
int a[3]={1,5,7},b[3]={11,22,33},c[6],i,j,k;
void main()
{
for(i=0,j=0,k=0;i<6;i++)
{
if(i%2==0)
{
c[i]=a[j];
j++;
}
else
{
c[i]=b[k];
k++;
}
printf("%d ",c[i]);
}
}
--------------------------------------------------------------------
(23)
#include<stdio.h>
int a[2]={1,5},b[4]={11,22,33,44},c[6],i,j,k,ele;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0,j=0,k=0;i<6;i++)
{
if(i%2==0 && j<ele)
{
c[i]=a[j];
j++;
}
else
{
c[i]=b[k];
k++;
}
printf("%d ",c[i]);
}
}
--------------------------------------------------------------------
(24)
#include<stdio.h>
int a[5]={99,88,77,66,55},in=0,i,ele;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=in;i<ele;i++)
{
a[i]=a[i+1];
}
for(i=0;i<ele-1;i++)
printf("%d ",a[i]);
}
--------------------------------------------------------------------
(25)
#include<stdio.h>
int a[5]={99,88,77,66,55},in=2,i,ele;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=in;i<ele;i++)
{
a[i]=a[i+1];
}
for(i=0;i<ele-1;i++)
printf("%d ",a[i]);
}
--------------------------------------------------------------------
(26)
#include<stdio.h>
int a[5]={99,88,77,66,55},in1=2,in2=3,i,ele;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
a[in1]=a[in1+1];
a[in2]=a[in2+1];
a[in1]=a[in1+1];
for(i=0;i<3;i++)
printf("%d ",a[i]);
printf("\n");
}
--------------------------------------------------------------------
(27)
#include<stdio.h>
int a[6]={11,12,14,13,15,18},c,ele,i;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0,c=0;i<ele;i++)
{
if(a[i]%2==0)
{
a[c]=a[i];
c++;
}
}
for(i=0;i<c;i++)
printf("%d ",a[i]);
printf("\n");
}
--------------------------------------------------------------------
(28)
#include<stdio.h>
int a[6]={-11,12,-14,13,-15,-18},c,ele,i;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0,c=0;i<ele;i++)
{
if(a[i]>0)
{
a[c]=a[i];
c++;
}
}
for(i=0;i<c;i++)
printf("%d ",a[i]);
printf("\n");
}
--------------------------------------------------------------------
(29) ****************************************************************UnderstandingUnderstandingUnderstandingUnderstanding
#include<stdio.h>
int a[10]={3,3,2,4,4,1,2,3,7,9},ele,i,j;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(j=i+1;j<ele;j++)
{
if(a[i]==a[j])
{
a[j]=0;;
}
}
}
for(i=0;i<ele;i++)
{
if(a[i]==0)
{
for(j=i;j<ele;j++)
{
a[j]=a[j+1];
}
ele--; //Whats happening
i--; //Whats happening
}
}
for(i=0;i<ele;i++)
printf("%d ",a[i]);
printf("\n");
}
--------------------------------------------------------------------
(30) ****************************************************************UnderstandingUnderstandingUnderstandingUnderstanding
#include<stdio.h>
int a[10]={3,3,2,4,4,2,5,3,4,9},ele,i,j;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(j=i+1;j<ele;j++)
{
if(a[i]==a[j] && a[i]%2==0)
{
a[j]=0;
}
}
}
for(i=0;i<ele;i++)
{
if(a[i]==0)
{
for(j=i;j<ele;j++)
{
a[j]=a[j+1];
}
i--; //Whats happening
ele--; //Whats happening
}
}
for(i=0;i<ele;i++)
printf("%d ",a[i]);
printf("\n");
}
--------------------------------------------------------------------
(31)
#include<stdio.h>
int a[10]={3,3,2,4,4,2,5,3,4,9},ele,i,j,c;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(j=i,c=0;j<ele;j++)
{
if(a[i]==a[j] && a[i]!=0)
{
c++;
if(c>1)
a[j]=0;
}
}
if(c>1)
printf("%d repeated %d times\n",a[i],c);
}
}
--------------------------------------------------------------------
(32)
#include<stdio.h>
int a[5]={11,202,234,456,90},ele,i,r,mul,num;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(num=a[i],r,mul=1;num;num=num/10)
{
r=num%10;
mul=mul*r;
}
a[i]=mul;
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(33)
#include<stdio.h>
int a[4]={4,5,6,4},ele,i,fact,num;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(num=a[i],fact=1;num>=1;num--)
{
fact=fact*num;
}
a[i]=fact;
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(34)
#include<stdio.h>
int a[7]={3,4,5,6,7,8,9},ele,i,j,c=0;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(j=2;j<a[i];j++)
{
if(a[i]%j==0)
break;
}
if(a[i]==j)
{
printf("%d\n",a[i]);
c++;
}
}
printf("Prime numbers are : %d",c);
}
--------------------------------------------------------------------
(35)
#include<stdio.h>
int a[7]={3,4,5,6,7,28,9},ele,i,j,c=0,add;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(j=1,add=0;j<a[i];j++)
{
if(a[i]%j==0)
{
add=add+j;
}
}
if(add==a[i])
{
printf("%d\n",a[i]);
c++;
}
}
printf("Perfect Numbers are : %d\n",c);
}
--------------------------------------------------------------------
(36)
#include<stdio.h>
int a[7]={2,4,2,6,145,28,1},ele,i,c=0,num,r,add,fact;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(num=a[i],r=0,add=0;num;num=num/10)
{
r=num%10;
for(fact=1;r>=1;r--)
{
fact=fact*r;
}
add=add+fact;
}
if(a[i]==add)
{
printf("%d\n",a[i]);
c++;
}
}
printf("Strong Numbers are : %d\n",c);
}
--------------------------------------------------------------------
(37)
#include<stdio.h>
int a[7]={22,4,21,6,153,28,11},ele,i,d,num,add,mul,k,r,c=0;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(num=a[i],d=0;num;num=num/10,d++);
for(num=a[i],add=0;num;num=num/10)
{
r=num%10;
for(k=1,mul=1;k<=d;k++)
{
mul=mul*r;
}
add=add+mul;
}
if(add==a[i])
{
printf("%d\n",a[i]);
c++;
}
}
printf("Armstrong Numbers are : %d\n",c);
}
--------------------------------------------------------------------
(38)
#include<stdio.h>
int a[7]={11,21,31,41,51,61,71},rotate=1,ele,i,j,temp;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<rotate;i++)
{
temp=a[ele-1];
for(j=ele-1;j>0;j--)
{
a[j]=a[j-1];
}
a[0]=temp;
}
for(i=0;i<ele;i++)
{
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(39)
#include<stdio.h>
int a[7]={11,21,31,41,51,61,71},rotate=3,ele,i,j,temp;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<rotate;i++)
{
temp=a[ele-1];
for(j=ele-1;j>0;j--)
{
a[j]=a[j-1];
}
a[0]=temp;
}
for(i=0;i<ele;i++)
{
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(40)
#include<stdio.h>
int a[7]={11,21,31,41,51,61,71},rotate=1,ele,i,j,temp;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<rotate;i++)
{
temp=a[0];
for(j=0;j<ele;j++)
{
a[j]=a[j+1];
}
a[ele-1]=temp;
}
for(i=0;i<ele;i++)
{
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(41)
#include<stdio.h>
int a[7]={11,21,31,41,51,61,71},rotate=2,ele,i,j,temp;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<rotate;i++)
{
temp=a[0];
for(j=0;j<ele;j++)
{
a[j]=a[j+1];
}
a[ele-1]=temp;
}
for(i=0;i<ele;i++)
{
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(42)
#include<stdio.h>
int a[7]={-1,22,3,-4,-8,33,77};
int i,ele,k;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=ele,k=ele-1;i>=0;i--)
{
if(a[i]<0)
{
a[i]=a[i]^a[k];
a[k]=a[i]^a[k];
a[i]=a[i]^a[k];
k--;
}
}
for(i=0;i<ele;i++)
{
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(43)
#include<stdio.h>
int a[7]={11,22,22,44,55,33,88};
int i,ele,k;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=ele,k=ele-1;i>=0;i--)
{
if(a[i]%2!=0)
{
a[i]=a[i]^a[k];
a[k]=a[i]^a[k];
a[i]=a[i]^a[k];
k--;
}
}
for(i=0;i<ele;i++)
{
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(44)
#include<stdio.h>
int i,ele,j,k,c=0;
int a[9]={11,0,0,44,0,33,0},b[9];
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
if(a[i]==0)
c++;
}
j=0;
k=c;
for(i=0;i<ele;i++)
{
if(a[i]==0)
{
b[j]=0;
j++;
}
else
{
b[c]=a[i];
c++;
}
}
for(i=0;i<ele;i++)
{
a[i]=b[i];
}
for(i=0;i<ele;i++)
{
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(45)
#include<stdio.h>
int a[5]={2,4,6,28,6},ele,i,j,c=0,add;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(j=1,add=0;j<a[i];j++)
{
if(a[i]%j==0)
{
add=add+j;
}
}
if(add==a[i])
{
printf("%d\n",a[i]);
break;
}
}
printf("Perfect Number index : %d\n",i);
}
--------------------------------------------------------------------
(46)
#include<stdio.h>
int a[7],i,j,c=0,ele;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=2;c<7;i++)
{
for(j=2;j<i;j++)
{
if(i%j==0)
break;
}
if(i==j)
{
a[c]=i;
c++;
}
}
for(i=0;i<ele;i++)
printf("%d ",a[i]);
}
--------------------------------------------------------------------
(47)****************************************************************UnderstandingUnderstandingUnderstandingUnderstanding
#include<stdio.h>
int a[7]={6,6,7,28,6,5,24},i,j,add,ele;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(j=1,add=0;j<a[i];j++)
{
if(a[i]%j==0)
{
add=add+j;
}
}
if(add==a[i])
{
a[i]=0;
}
}
for(i=0;i<ele;i++)
{
if(a[i]==0)
{
for(j=i;j<ele;j++)
{
a[j]=a[j+1];
}
ele--;
i--;
}
}
for(i=0;i<ele;i++)
{
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(48)
#include<stdio.h>
int a[8]={11,22,33,44,55,66,77,88},ele,i,j,c=0;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=2;c<ele;i++)
{
for(j=2;j<i;j++)
{
if(i%j==0)
break;
}
if(i==j)
{
a[i]=0;
c++;
}
}
for(i=0;i<ele;i++)
printf("%d ",a[i]);
}
--------------------------------------------------------------------
(49)
#include<stdio.h>
int a[8]={11,22,33,44,55,66,77,88},b[8],ele,i,j,c=0,k=0;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=2;i<ele;i++)
{
for(j=2;j<i;j++)
{
if(i%j==0)
break;
}
if(i==j)
{
b[k]=a[i];
c++;
k++;
}
}
for(i=0;i<c;i++)
printf("%d ",b[i]);
}
--------------------------------------------------------------------
(50)****************************************************************UnderstandingUnderstandingUnderstandingUnderstanding
#include<stdio.h>
int a[6]={2,145,2,14,3,2},num,r,i,j,mul,add,ele;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(i=0;i<ele;i++)
{
for(num=a[i],add=0;num;num=num/10)
{
r=num%10;
for(mul=1;r>=1;r--)
{
mul=mul*r;
}
add=add+mul;
}
if(a[i]==add)
{
a[i]=0;
}
}
for(i=0;i<ele;i++)
{
if(a[i]==0)
{
for(j=i;j<ele;j++)
{
a[j]=a[j+1];
}
ele--;
i--;
}
}
for(i=0;i<ele;i++)
{
printf("%d ",a[i]);
}
}
--------------------------------------------------------------------
(51)****************************************************************UnderstandingUnderstandingUnderstandingUnderstanding
#include<stdio.h>
int a[6]={22,141,222,45,33,77},rev,i,j,r,ele;
void main()
{
ele=sizeof(a)/sizeof(a[0]);
for(j=0;j<ele;j++)
{
for(i=a[j],rev=0;i;i=i/10)
{
r=i%10;
rev=rev*10+r;
}
if(a[j]==rev && rev%2!=0)
{
a[j]=0;
}
}
for(i=0;i<ele;i++)
{
if(a[i]==0)
{
for(j=i;j<ele;j++)
{
a[j]=a[j+1];
}
ele--;
i--;
}
}
Comments
Post a Comment