HomeWork 4
صفحة 1 من اصل 1
HomeWork 4
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;}
صفحة 1 من اصل 1
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى
3/7/2011, 11:05 pm من طرف anas mohtaseb
» امتحان الفاينال لمختبر برمجة الحاسوب
26/5/2011, 1:45 pm من طرف Basel Tamimi
» حل سؤال الموظفين والرواتب
22/5/2011, 3:17 pm من طرف Basel Tamimi
» sum program with parameters
22/5/2011, 9:33 am من طرف Basel Tamimi
» مختبر 9
18/5/2011, 5:43 pm من طرف Basel Tamimi
» سلايدات الكتاب للاقسام 4 5 7
6/5/2011, 2:07 pm من طرف Basel Tamimi
» شكرا لكم
4/5/2011, 8:51 pm من طرف anas mohtaseb
» Programming Assignment الحل الثاني
2/5/2011, 7:58 am من طرف Basel Tamimi
» سؤال على ال parallel arrays
1/5/2011, 5:06 am من طرف Basel Tamimi