Advertisement
semsem_elazazy

Untitled

Dec 13th, 2021
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  int n,m;
  9.  
  10.  while(1)
  11.  {
  12.    cin>>n>>m;
  13.  if(n<=0||m<=0)
  14.  break;
  15.  if(m>n)
  16.  {
  17.         int s=0;
  18.         for(int i=n;i<=m;i++)
  19.         {
  20.                 cout<<i<<" ";
  21.                 s=s+i;
  22.         }
  23.         cout<<"sum ="<<s;
  24.         cout<<endl;
  25.  }    
  26.  if(n>m)
  27.  {
  28.         int k=0;
  29.         for(int j=m;j<=n;j++)
  30.         {
  31.                 cout<<j<<" ";
  32.                 k=k+j;
  33.         }
  34.      cout<<"sum ="<<k;
  35.      cout<<endl;      
  36. }
  37. }
  38.  
  39.  
  40.  
  41.        
  42.     return 0;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement