ملتقى البرمجة
اهلا بك زائرنا الكريم ..
اذا كانت هذه هيالزيارة الاولى لك فاننا ندعوك الى التسجيل بالمنتدى او التعريف بنفسك
مع العلم ان الزوار لا يستطيعون مشاهدة كل المواضيع المطروحة بالمنتدى


انضم إلى المنتدى ، فالأمر سريع وسهل

ملتقى البرمجة
اهلا بك زائرنا الكريم ..
اذا كانت هذه هيالزيارة الاولى لك فاننا ندعوك الى التسجيل بالمنتدى او التعريف بنفسك
مع العلم ان الزوار لا يستطيعون مشاهدة كل المواضيع المطروحة بالمنتدى
ملتقى البرمجة
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.

HomeWork 4

اذهب الى الأسفل

HomeWork 4 Empty HomeWork 4

مُساهمة من طرف Basel Tamimi 4/4/2011, 2:02 pm

Q)) write a c++ program to read in
some characters and store them in a
character array. Then your program
should shift-right the givin
charactorsbased on the number
determined by the user.
Such as shift-right 5 means
rotate the charactors 5 locations
circularly to right direction.

solution:

الكود:
#include <iostream>
#define size 10
using namespace std;
int main (){
int counter,num_of_shifting,counter2=1;
char sentence[size],shifted_sentence[size];

//input word & num of shifting
cout<<"enter an 10 char's word: ";
for(counter=0;counter<size;counter++)
cin.get(sentence[counter]);
cout<<"enter number of shifting: ";
cin>>num_of_shifting;

//process
while(counter2<=num_of_shifting){
for(counter=0;counter<size-1;counter++)
shifted_sentence[counter+1]=sentence[counter];
shifted_sentence[0]=sentence[size-1];
for(counter=0;counter<size;counter++)
sentence[counter]=shifted_sentence[counter];
counter2++;}
cout<<endl;

//output word
cout<<"the output word is: ";
for(counter=0;counter<size;counter++)
cout<<shifted_sentence[counter];
cout<<endl<<endl;
system ("pause");
return 0;}
Basel Tamimi
Basel Tamimi

عدد المساهمات : 44
تاريخ التسجيل : 09/03/2011
العمر : 32
الموقع : الخليل

https://is-it1.alafdal.net/

الرجوع الى أعلى الصفحة اذهب الى الأسفل

الرجوع الى أعلى الصفحة

- مواضيع مماثلة

 
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى