Home

Learn Programming & Prepare for NPTEL Exams... Swayam Solver is your one-stop destination for NPTEL exam preparation.

An Introduction to Programming through C++ | Week 3 Programming Assignment | Jan-2022 | NPTEL

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.