اكتب برنامج C لقراءة مصفوفة طولها 6 وإيجاد أصغر عنصر وموضعه

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

اكتب برنامج C لقراءة مصفوفة طولها 6 وإيجاد أصغر عنصر وموضعه

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

Input the length of the array: 5 Input the array elements:
25
35
20
14
45
Smallest Value: 14
Position of the element: 3

الأجوبة

/*Write a C program to read an array of length 6 and find the smallest element and its position*/

#include <stdio.h>
int main() {
	int e, i, sval, position;

	printf("\nInput the length of the array: ");
	scanf("%d", &e);

	int v[e];
    printf("\nInput the array elements:\n ");
	for(i = 0; i < e; i++) {
			scanf("%d", &v[i]);
	}
	sval = v[0];
	position = 0;
	for(i = 0; i < e; i++) {
		if(sval > v[i]) {
			sval = v[i];
			position = i;
		}
	}
	
	printf("Smallest Value: %d\n", sval);
	printf("Position of the element: %d\n", position);
	return 0;
}
هل كان المحتوى مفيد؟

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

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