Page 16 - PROGRAMMING IN C_Neat
P. 16

10. Write a program to find the smallest of n numbers using array.  OR    Write a program to read n
        numbers and find the minimum number using array. *

        Program to find the smallest of n numbers:
        #include <stdio.h>

        main()
        {
               int  i, n, small;
               int  a[10];

               scanf(“%d”, &n);
               for( i=0; i<n; i++)
               {
                       scanf(“%d”, &a[i]);
               }

               small = a[0];
               for( i=1; i<n; i++)
               {
                       if(a[i] < small)
                              small = a[i];
               }

               printf(“Smallest Number = %d”, small);
        }

        Input    Output
        3  n    Smallest Number = 6

        7
        8
        6
        _______________________________________________________________________________________

        11. Write a program for matrix addition.           OR     Write a program to add two matrices. *

        Program for Matrix Addition:
        #include <stdio.h>

        main()
        {
               int  a[10][10], b[10][10], c[10][10];
               int  i, j, m, n, p, q;

               scanf(“%d  %d”, m, n);
               scanf(“%d  %d”, p, q);

               if((m == p) && (n == q))
               {
                       for( i=0; i<m; i++)
                              for( j=0; j<n; j++)
                                     scanf(“%d”, &a[i][j]);
   11   12   13   14   15   16   17   18   19   20   21