Use app×
QUIZARD
QUIZARD
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
4.2k views
in Computer by (69.2k points)

Write a function rightrot(x, n) that returns the value of the integer x rotated to the right by n positions.

1 Answer

+1 vote
by (70.0k points)
selected by
 
Best answer

A function rightrot(x, n) that returns the value of the integer x rotated to the right by n positions.

 #include<conio.h>

rightrot(x,n)

{

int x,n,k=0,num,rem,i,j,dig;

int arr1[10],arr2[10];

clrscr();

printf("\n Enter the integer to be rotated : ");

scanf("%d",&x); 

printf("\n Enter the positions by which %d is to be rotated : ",x)

scanf("%d",&n);

for(num=x;num!=0;num/=10)

{

rem=num%10;

arr1[k++]=rem

}

i=k-1;

k=0;

for(;i>=0;i--)

arr2[k++]=arr1[i];

k-=1;

for(i=1;i<=n;i++)

{

dig=arr2[k];

for(j=k;j>0;j--)

arr2[j]=arr2[j-1];

arr2[0]=dig;

}

printf("\n\n The original number is : “); return x;

printf("\n The rotated number is : ");

for(i=0;i<=k;i++)

printf("%d",arr2[i]);

getch();

}  

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...