1d array
1. A left rotation operation on an array of size n shifts each of the array's elements 1 unit to the left. For example, if 2 left rotations are performed on array [1,2,3,4,5], then the array would become [3,4,5,1,2]. Given an array of n integers and a number, d, perform d left rotations on the array. Then print the updated array as a single line of spaceseparated integers. Sol: #include<stdio.h> int main() { int i,s,j,t; long long int n; scanf("%lld",&n); int a[n]; scanf("%d",&s); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(j=1;j<=s;j++) { t=a[0]; for(i=0;i<=n-1;i++) { a[i]=a[i+1]; } a[n-1]=t; } for(i=0;i<n;i++) { printf("%d ",a[i]); } return 0; } 2. Develop a program to accept the age of n students of class, rearrange the data in ascending order and display the age of youngest and eldest stu...
Comments
Post a Comment