Viết chương trình nhập vào 1 mảng số nguyên và n, xoay trái mảng số nguyên n lần.

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void hoanvi(int& a,int& b);
void main()
{
int a[1000],n,m,i,dem;
printf(“nhap vao so phan tu cua mang n=”);
scanf(“%d”,&n);
srand(time(0));
for(i=0;i<n;i++)
{
a[i]=rand()%11;
printf(“%d “,a[i]);
}
printf(“nhap vao so lan xoay m=”);
scanf(“%d”,&m);
dem=1;
while(dem<=m)
{
for(i=0;i<n-1;i++)
{
hoanvi(a[i],a[i+1]);
}
printf(“xoay lan %d:”,dem);
for(i=0;i<n;i++)
{
printf(“%d “,a[i]);
}
printf(“\n”);
dem++;

}
}
void hoanvi(int& a,int& b)
{
int tam;
tam=b;
b=a;
a=tam;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s