3-mavzu: Pointer Uyga vazifa


Download 57.54 Kb.
Sana18.06.2023
Hajmi57.54 Kb.
#1587607
Bog'liq
6f7857b6-6aa0-4ab0-aec9-279574c21461 Pointer-darsi-vazifasi (2)


3-mavzu: Pointer


Uyga vazifa:

1) Butun toifali pointer orqali int seriyaning maksimal qiymatini toping. (FAQAT POINTER(YA'NI QO'SHIMCHA O'ZGARUVCHISISIZ) VA BITTA SERIYA ISHLARISH KERAK VA SERIYANING ELEMENTLARI O'ZGARMASLIGI KERAK)


Input: A[5]={1,2,3,4,5}
Output: 5

#include
#include

int main()


{
int arr[5] = {225,326,-45,85,-92};
int *max = &arr[0];
for (int i = 0; i < 5; i++)
{

if (*max < arr[i])


{
*max = arr[i];
}
}
printf("%p manzildagi son qiymat %d ga teng\n",&max,*max);
return 0;
}



2) Haqiqiy son toifali pointer orqali float tipidagi sonning butun qismini chiqaring. (FAQAT POINTER(YA'NI QO'SHIMCHA O'ZGARUVCHISISIZ) VA BITTA O'ZGARUVCHI ISHLARISH KERAK)


Input: son=12.345
Output: 12

int main()
{
int arr[5]={1,2,3,4,5};
int *sum=&arr[0];
for(int i = 1; i < 5; i++)
{
*sum +=arr[i];
}
printf("sum=%i",*sum );
return 0;



3) Butun toifali pointer orqali int seriya elementlarining yig'indisini toping. (FAQAT POINTER(YA'NI QO'SHIMCHA O'ZGARUVCHISISIZ) VA BITTA SERIYA ISHLARISH KERAK VA SERIYANING ELEMENTLARI O'ZGARMASLIGI KERAK)


Input: A[5]={1,2,3,4,5}
Output: 15

int main()
{
float arr[5]={1.3,2.2,3.6,4.2,5.5};
float *sum=&arr[0];
for(int i = 1; i < 5; i++)
{
*sum +=arr[i];
}
printf("sum=%f",*sum );
return 0;
}



4) Butun toifali pointer orqali int seriyaning birinchi va oxirgi qiymatlarini almashtiring. (FAQAT POINTER(YA'NI QO'SHIMCHA O'ZGARUVCHISISIZ) VA BITTA SERIYA ISHLARISH KERAK)


Input: A[5]={1,2,3,4,5}
Output: A[5]={5,2,3,4,1}

int main(){


int arr[5]={1,2,3,4,5};


for(int i=0; i < 5; i++)
{
printf("%i,",arr[i]);
}
printf("\n Almashtirlgan qiymatlar:\n");
int *swap = &arr[0];
arr[1] = *swap;
*swap = arr[4];
arr[0] = *swap;
arr[4] = arr[1];
for(int i=0; i < 5; i++)
{
printf("%i,",arr[i]);
}

return 0;


}



5) Butun toifali pointer orqali int seriyaning maksimal va minimal qiymatlarini almashtiring. (FAQAT POINTER(YA'NI QO'SHIMCHA O'ZGARUVCHISISIZ) VA BITTA SERIYA ISHLARISH KERAK)


Input: A[5]={1,2,3,4,5}
Output: A[5]={5,2,3,4,1}







Download 57.54 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling