0% found this document useful (0 votes)
10 views2 pages

7 One Dimensional Array حل-1

Uploaded by

morshidwww2022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

7 One Dimensional Array حل-1

Uploaded by

morshidwww2022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Fundamentals of Computer Programming UNIVERSITY OF SCIENCE & TECHNOLOGY

Faculty of Engineering
2nd Level Dep. of Electronics
Engineering
Programming Sheet # 7
(One Dimensional Arrays)
1) Write a program to declare one dimensional array with five integer numbers, then initialize this array and
print it.
#include<stdio.h>
main()
{
int x[5]={1,2,3,4,5};
printf("%d\t%d\t%d\t%d\t%d",x[0],x[1],x[2],x[3],x[4]);
}

2) Write a program to declare one dimensional array with five float numbers, then take the elements from user
and print it in reverse.
#include<stdio.h>
main()
{
float x[5];
int i;
printf("Please enter five float numbers\n");
for(i=0;i<=4;i++)
scanf("%f",&x[i]);

for(i=4;i>=0;i--)
printf("%f\t",x[i]);
}

3) Write a program to declare one dimensional array with ten int numbers, then take the elements from user
and print the sum and the average of this array.
#include<stdio.h>
main()
{
int x[10],i,sum=0;
float ave;
printf("Please enter ten integer numbers\n");
for(i=0;i<=9;i++)
scanf("%d",&x[i]);

for(i=0;i<=9;i++)
sum+=x[i];

ave=sum/10.0;
printf("Sum = %d\t Average = %f",sum,ave);
}
Sheet #7 - One Dimensional Arrays Eng. Ali Al-Ashwal 1
4) Write a program to declare one dimensional array with ten float numbers, then take the elements from user
and print the largest and smallest numbers from this array.
#include<stdio.h>
main()
{
float x[10],large,small;
int i;

printf("Please enter ten float numbers\n");


for(i=0;i<=9;i++)
scanf("%f",&x[i]);

large=small=x[0];
for(i=1;i<=9;i++)
{
if(x[i]>large)
large=x[i];
if(x[i]<small)
small=x[i];
}

printf("large = %f\t small = %f",large,small);


}

5) Write a program to declare one dimensional array with ten double numbers, then take the elements from
user and print the order of this array in ascending order.

#include<stdio.h>
main()
{
double x[10],temp;
int i,j;
printf("Please enter ten double numbers\n");
for(i=0;i<=9;i++)
scanf("%lf",&x[i]);

for(i=0;i<=9;i++)
for(j=i+1;j<=9;j++)
if(x[i]>x[j])
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}

for(i=0;i<=9;i++)
printf("%lf\t",x[i]);
}

Sheet #7 - One Dimensional Arrays Eng. Ali Al-Ashwal 2

You might also like