An Introduction to Programming Through C++
---------------------------------------------------------
Due on 2022-02-17, 23:59 IST
---------------------------------
Programming Assignment 3.1
---------------------------------
#include<iostream>
using namespace std;
int main()
{
char ch='A';
int x=0,y=0,number_of_steps;
while(ch!='E')
{
cin>>ch>>number_of_steps;
if(ch=='R')
x+=number_of_steps;
if(ch=='L')
x-=number_of_steps;
if(ch=='U')
y+=number_of_steps;
if(ch=='D')
y-=number_of_steps;
}
cout<<x<<" "<<y<<endl;
return 0;
}
---------------------------------
Programming Assignment 3.2
---------------------------------
#include<iostream>
using namespace std;
int main()
{
int n,sum=0;
cin>>n;
while(n!=0)
{
sum+=n%10;
n/=10;
}
cout<<sum<<endl;
return 0;
}
----------------------------------------------------------
No comments:
Post a Comment
Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.