-->

Write a program to show initialization of element in an array

using turbo c++
--------------------------------------------------------------------------------------------------
//Write a program to show initialization of element in an array
#include<stdio.h>
#include<conio.h>
void main()
{
float arr[4]={1,2,3,4},k;                                                                        // array declaration with 4 elements
                                                                                                         // can also be written as arr[]
printf("elements are\n");
for(k=0;k<=3;k++)
{
   printf(" element for location=%d is\n",k);                               // for elements in particular location
   printf("%f",arr[k]);
}
getch();
}

------------------------------------------------------------------------------------------------------------------------------------------

using codeblocks or dev c++/online compiler
---------------------------------------------------------------------------------------------------------------------------------------
//Write a program to show initialization of element in an array

#include<stdio.h>
int main()
{
float arr[4]={1,2,3,4},k;                                                                        // array declaration with 4 elements
                                                                                                         // can also be written as arr[]
printf("elements are\n");
for(k=0;k<=3;k++)
{
   printf(" element for location=%d is\n",k);                               // for elements in particular location
   printf("%f",arr[k]);
}
return 0;
}

WAP to search an element stored in an array.



using turbo c++
----------------------------------------------------------------------------------------------------------
// program to search an element in an array

#include <stdio.h>
#include<conio.h>
void main()
{
    int a[100],n,i,number,location,j,found;
    printf("enter total number\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter number for location=%d\n",i);
        scanf("%d",&a[i]);
    }
    printf("numbers before search, are:\n");
    for(i=0;i<n;i++)
    {
        printf("%d\n",a[i]);
    }
    printf("enter number  to be searched\n");
    scanf("%d",&number);
    for(i=0;i<n;i++)
    {
        if(number==a[i])
        {
            found=0;
            break;
        }
        else
        {
            found=1;
        }
    }
    if(found==0)
    {
    printf("number found and number %d location is %d\n",number,i);
    }
    else
    {
        printf("given number is not in the list");
    }
    getch();
}

-----------------------------------------------------------------------------------------------------------------
using codeblocks/dev c++/online compiler
----------------------------------------------------------------------------------------------------------------
// program to search an element in an array

#include <stdio.h>

int main()
{
    int a[100],n,i,number,location,j,found;
    printf("enter total number\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter number for location=%d\n",i);
        scanf("%d",&a[i]);
    }
    printf("numbers before search, are:\n");
    for(i=0;i<n;i++)
    {
        printf("%d\n",a[i]);
    }
    printf("enter number's  to be searched\n");
    scanf("%d",&number);
    for(i=0;i<n;i++)
    {
        if(number==a[i])
        {
            found=0;
            break;
        }
        else
        {
            found=1;
        }
    }
    if(found==0)
    {
    printf("number found and number %d location is %d\n",number,i);
    }
    else
    {
        printf("given number is not in the list");
    }
    return 0;

}

program to count total positive elements among 'n' elements.

using turbo C++
-----------------------------------------------------------------------
// program to count total positive elements among 'n' elements.
#include <stdio.h>
#include<conio.h>
void main()
{
    int a[100],n,i,count=0;
    printf("enter total number\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter number for location=%d\n",i);
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        if(a[i]>0)
                {
                   count++;
                 }
    }
 printf("total positive elements is=%d",count);
    getch();
}
-------------------------------------------------------------------------------------------------------------------
using online compiler/devC++/codeblocks with return concept
---------------------------------------------------------------------------------------------------------------------
// program to count total positive elements among 'n' elements.
#include <stdio.h>

int main()
{
    int a[100],n,i;
    printf("enter total number\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter number for location=%d\n",i);
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
          if(a[i]>0)
                {
                   count++;
                 }
    }
       printf("total positive elements is=%d",count);
    return 0;
}

program to get difference of all elements of two one dimensional arrays.

using turbo c++
----------------------------------------------------------------------------------------------------------
//program to get difference of all elements of two one dimensional arrays.
#include<stdio.h>
#include<conio.h>
void main()
{
int array_1[100],array_2[100];
int i;
int total_element;
printf("enter size of array\n");
scanf("'%d",&total_element);
printf("enter elements of first array\n");
for(i=0;i<total_element;i++)
{

           scanf("%d",&array_1[i]);
  }

printf("now enter for second array\n");
for(i=0;i<total_element;i++)
{
 
           scanf("%d",&array_2[i]);
}
 printf("the summed array is\n");
for(i=0;i<total_element;i++)
{
           printf("%d\n",array_1[i]-array_2[i]);
}
getch();
}

--------------------------------------------------------------------------------------------------------
using codeblocks or dev c++/online compiler
-------------------------------------------------------------------------------------------------
//program to get difference of all elements of two one dimensional arrays.
#include<stdio.h>
int main()
{
int array_1[100],array_2[100];
int i;
int total_element;
printf("enter size of array\n");
scanf("'%d",&total_element);
printf("enter elements of first array\n");
for(i=0;i<total_element;i++)
{

           scanf("%d",&array_1[i]);
  }

printf("now enter for second array\n");
for(i=0;i<total_element;i++)
{
 
           scanf("%d",&array_2[i]);
}
 printf("the summed array is\n");
for(i=0;i<total_element;i++)
{
           printf("%d\n",array_1[i]-array_2[i]);
}
return 0;
}




program to get sum of all elements of two one dimensional arrays.

using turbo c++
----------------------------------------------------------------------------------------------------------
//program to get sum of all elements of two one dimensional arrays.
#include<stdio.h>
#include<conio.h>
void main()
{
int array_1[100],array_2[100];
int i;
int total_element;
printf("enter size of array\n");
scanf("'%d",&total_element);
printf("enter elements of first array\n");
for(i=0;i<total_element;i++)
{

           scanf("%d",&array_1[i]);
  }

printf("now enter for second array\n");
for(i=0;i<total_element;i++)
{
 
           scanf("%d",&array_2[i]);
}
 printf("the summed array is\n");
for(i=0;i<total_element;i++)
{
           printf("%d\n",array_1[i]+array_2[i]);
}
getch();
}

--------------------------------------------------------------------------------------------------------
using codeblocks or dev c++/online compiler
-------------------------------------------------------------------------------------------------
//program to get sum of all elements of two one dimensional arrays.
#include<stdio.h>
int main()
{
int array_1[100],array_2[100];
int i;
int total_element;
printf("enter size of array\n");
scanf("'%d",&total_element);
printf("enter elements of first array\n");
for(i=0;i<total_element;i++)
{

           scanf("%d",&array_1[i]);
  }

printf("now enter for second array\n");
for(i=0;i<total_element;i++)
{
 
           scanf("%d",&array_2[i]);
}
 printf("the summed array is\n");
for(i=0;i<total_element;i++)
{
           printf("%d\n",array_1[i]+array_2[i]);
}
return 0;
}




program to store any 'n' elements and display those which are >15.

using turbo C++
-----------------------------------------------------------------------
// program to store any 'n' elements and display those which are >15.
#include <stdio.h>
#include<conio.h>
void main()
{
    int a[100],n,i;
    printf("enter total number\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter number for location=%d\n",i);
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        if(a[i]>15)
                {
                   printf("%d\n",a[i]);
                 }
    }
    getch();
}
-------------------------------------------------------------------------------------------------------------------
using online compiler/devC++/codeblocks with return concept
---------------------------------------------------------------------------------------------------------------------
// program to store any 'n' elements and display those which are >15.
#include <stdio.h>

int main()
{
    int a[100],n,i;
    printf("enter total number\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter number for location=%d\n",i);
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
          if(a[i]>15)
                {
                   printf("%d\n",a[i]);
                 }
    }
    return 0;
}

program to swap any two values stored in array.Let there are 'n' numbers.


using turbo c++
-----------------------------------------------------------------------------------------------------------------------

//program to swap any two values stored in array.Let there are 'n' numbers.

#include <stdio.h>
#include<conio.h>
void main()
{
    int a[100],n,i,location,location1,j;
    printf("enter total number\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter number for location=%d\n",i);
        scanf("%d",&a[i]);
    }
    printf("numbers before swapping, are:\n");
    for(i=0;i<n;i++)
    {

        printf("%d\n",a[i]);
                 
    }
    printf("enter number's first location to be swapped\n");
    scanf("%d",&location);
    printf("enter number's second location to be swapped\n");               
    scanf("%d",&location1);                                                 
    j=a[location-1];
    a[location-1]=a[location1-1];
    a[location1-1]=j;
    printf("numbers after swapping, are:\n");
    for(i=0;i<n;i++)
    {

        printf("%d\n",a[i]);
                 
    }
    
    getch();


}

-----------------------------------------------------------------------------------------------------------------------
using codeblocks/dev c++/online compiler with return concept
---------------------------------------------------------------------------------------------------------
//program to swap any two values stored in array.Let there are 'n' numbers.

#include <stdio.h>

int main()
{
    int a[100],n,i,location,location1,j;
    printf("enter total number\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter number for location=%d\n",i);
        scanf("%d",&a[i]);
    }
    printf("numbers before swapping, are:\n");
    for(i=0;i<n;i++)
    {

        printf("%d\n",a[i]);
                 
    }
    printf("enter number's first location to be swapped\n");
    scanf("%d",&location);
    printf("enter number's second location to be swapped\n");               
    scanf("%d",&location1);                                                 
    j=a[location-1];
    a[location-1]=a[location1-1];
    a[location1-1]=j;
    printf("numbers after swapping, are:\n");
    for(i=0;i<n;i++)
    {

        printf("%d\n",a[i]);
                 
    }
    
    return 0;

}