Sunday, September 22, 2013

Arrays C-Programs

"ARRAYS---Chapter No. 5"
Question No. 5:
#include<stdio.h>
#include<conio.h>
void main(void)
{
                clrscr();
                int arr[80],small,loc,m;
                printf("Enter size of array but not more than80");
                scanf("%d",&m);
                printf("Enter elements of array");
                for(int i=0;i<m;i++)
                {
                                scanf("%d",&arr[i]);
                }
                small=arr[0];
                loc=0;
                for(i=0;i<m;i++)
                {
                                if(arr[i]<small)
                                {
                                small=arr[i];
                                loc=i;
                                }
                }
                printf("Smallest value is %d and is located at %d",small,loc);
                getch();
}


Question No. 6
#include<stdio.h>
#include<conio.h>
void main(void)
{
                clrscr();
                int a[5],b[5],sum=0;
                printf("Enter 5 integer values for a = ");
                for(int i=0;i<5;i++)
                {
                                scanf("%d",&a[i]);
                }
                printf("Enter 5 integer values for b = ");
                for(i=0;i<5;i++)
                {
                                scanf("%d",&b[i]);
                }
                for(i=0;i<5;i++)
                {
                                sum=sum+a[i]*b[i];
                }
                printf("Sum of Product = %d",sum);
                getch();
}
Question No. 7
#include<stdio.h>
#include<conio.h>
void main(void)
{
                clrscr();
                float arr[10],sum=0;
                printf("Enter 10 floating values = ");
                for(int i=0;i<10;i++)
                {
                                scanf("%f",&arr[i]);
                }
                for(i=0;i<10;i++)
                {
                                if(arr[i]>=0)
                                {
                                sum+=arr[i];
                                }
                }
                printf("Sum of Positive floating values = %f",sum);
                getch();
}
Question No.  8
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
                clrscr();
                float arr[60],gm,pro=1;
                int n;
                printf("enter the size of the array(max 60)");
                scanf("%d",&n);
                for(int i=0;i<n;i++)
                {
                printf("Enter floating value for array");
                scanf("%f",&arr[i]);
                }
                for(i=0;i<n;i++)
                {
                pro*=arr[i];
                }
                gm=pow(pro,(1/n));
                printf("GM = %f",gm);
                getch();
}
Question No. 9 (a)
#include<stdio.h>
#include<conio.h>
void main(void)
{
                clrscr();
                for(int i=1;i<=5;i++)
                {
                                for(int l=1;l<=i;l++)
                                {
                                printf("%d ",l);
                                }
                printf("\n");
                }
                getch();
}
Question No. 9 (b)
#include<stdio.h>
#include<conio.h>
void main(void)
{
                clrscr();
                for(int i=5;i>=1;i--)
                {
                                for(int l=1;l<=i;l++)
                                {
                                printf("%d ",l);
                                }
                printf("\n");
                }
                getch();
}
Question No. 9( C)
#include<stdio.h>
#include<conio.h>
void main(void)
{
                clrscr();
               
                for(int i=1;i<=5;i++)
                {

                                for(int l=i;l<=5;l++)
                                {
                                printf("%d ",l);
                                }
                printf("\n");
                }
                getch();
}
Question No.9 (d)
#include<stdio.h>
#include<conio.h>
void main(void)
{
                clrscr();
                for(int i=1;i<=5;i++)
                {
                                for(int l=1;l<=i;l++)
                                {
                                printf("*");
                                }
                printf("\n");
                }
                getch();
}
Question No. 10
#include<stdio.h>
#include<conio.h>
void main(void)
{
                clrscr();
                int x[3][3],r,c,sum,pro;
                printf("Enter 9 integer values for 3x3 matrix = ");
                for(r=0;r<3;r++)
                {
                                for(c=0;c<3;c++)
                                {
                                scanf("%d",&x[r][c]);
                                }
                }
                printf("\nResult\n");
                for(r=0;r<3;r++)
                {
                sum=0;pro=1;
                                for(c=0;c<3;c++)
                                {
                                                sum+=x[r][c];
                                                printf("%d\t",x[r][c]);
                                }
                printf("Sum = %d\n",sum);
                for(c=0;c<3;c++)
                                {
                                                pro*=x[r][c];
                                                printf("%d\t",x[r][c]);
                                }
                printf("Product = %d\n",pro);
                }
                getch();
}


No comments:

Post a Comment