اكتب برنامج C لحساب مجموع القيم في مصفوفة أعداد صحيحة ما عدا الرقم 17. قم بإرجاع 0 إذا كانت المصفوفة المعطاة لا تحتوي على عدد صحيح

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

اكتب برنامج C لحساب مجموع القيم في مصفوفة أعداد صحيحة ما عدا الرقم 17. قم بإرجاع 0 إذا كانت المصفوفة المعطاة لا تحتوي على عدد صحيح

الخرج المتوقع :

Sum of values in the array of integers except the number 17: 46

الأجوبة

/*Write a C program to compute the sum of values in a given array of integers except the number 17. Return 0 if the given array has no integer*/

#include <stdio.h>
#include <stdlib.h>
int main(void){
    int array1[] = {1, 2, 5, 7, 9, 10, 12, 17};
    int arr_size = sizeof(array1)/sizeof(array1[0]);
    printf("Sum of values in the array of integers except the number 17: ");
    printf("%d",test(array1, arr_size));
  }    
  int test(int nums[], int arr_size)
         {
            int sum = 0;

            for (int i = 0; i < arr_size; i++)
            {
                if (nums[i] != 17) sum += nums[i];
                else i++;
            }
            return sum;
         }
هل كان المحتوى مفيد؟

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

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