C Program to find sum of two numbers



#include<stdio.h>
#include<conio.h>
void main(){
int arr[10],small,i;
clrscr();
printf("Enter elements of array:");
for(i=0;i<10;i++)
{
printf("\nEnter element %d:",i+1);
scanf("%d",&arr[i]);
}
small=arr[0];
for(i=0;i<10;i++)
{
if(arr[i])
{
small=arr[i];
}
}
printf("\nSmallest element of array is:%d",small);
getch();
}

Explanation:

The above program will calculate the smallest element from an array. There is an array of ten elements. There is a 'for' loop which is executing from 0 to 9 and find the smallest elements among the 10 elements of array. We can understand this process by using following example: We can understand this process by using following example:

arr[0]=10,arr[1]=2,arr[2]=0,arr[3]=40,arr[4]=3,arr[5]=9,arr[6]=2,arr[7]=5,arr[8]=90,arr[9]=100 small=arr[0]=10
i=0;
i<10,True
iteration1:
(arr[0]=10)<(small=10),False
i=i+1=1
iteration 2:
(arr[1]=2)<(small=10),True
small=arr[1]=2
i=i+1=2
i<10,True
iteration 3:
(arr[2]=0)<(small=2),True
small=arr[2]=0
i=i+1=3
i<10,True
iteration 4:
(arr[3]=40)<(small=0),False
i=i+1=4
i<10,true
iteration 5:
(arr[4]=3)<(small=0),False
i=i+1=5
i<10,True
iteration 6:
(arr[5]=9)<(small=0),False
i=i+1=6
i<10,True
iteration 7:
(arr[6]=2)<(small=0),False
i=i+1=7
i<10,true
iteration 8:
(arr[7]=5)<(small=0),False
i=i+1=8
i<10,true
iteration 9:
(arr[8]=90)<(small=0),False
i=i+1=9
i<10,true
iteration 10:
(arr[9]=100)<(small=0),False
i=i+1=10
i<10,false
loop break;
so finally smallest of element of given array is :0
The output of the above program is given below:

Output:

c program