Write a C++ program to get the absolute difference between n and 51. If n is greater than 51 return triple the absolute difference

  • برمجة سي بلس بلس
  • برمجة

Write a C++ program to get the absolute difference between n and 51. If n is greater than 51 return triple the absolute difference

Sample Output:

6
21
0

الأجوبة

#include <iostream>

using namespace std;

int test(int n)
        {
            const int x = 51;

            if (n > x)
            {
                return (n - x)*3;
            }
            return x - n;
        }
        
        
int main() 
 {
  cout << test(53) << endl;  
  cout << test(30) << endl;  
  cout << test(51) << endl;  
  return 0;    
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...