-->

program to enter any four elements and display that.

 //program to enter any four elements and display that.
#include<stdio.h>
#include<conio.h>
void main()
{
float arr[20],k;                                                                        // array declaration with maximum limit 20
float n,size;                                                                                  // says about size of array to be entered

printf("enter size of array\n");
scanf("%f",&size);
for(k=0;k<size;k++)
{
   printf("enter element for location=%d\n",k);                           // for elements in particular location
   scanf("%f",&arr[k]);
}
printf("elements are\n");
for(k=0;k<size;k++)
{
   printf(" element for location=%d is\n",k);                               // for elements in particular location
   printf("%f",arr[k]);
}

getch();
}



Array collection

Here are collection of programs using Array. Programs are written using one and two-dimensional. 

one dimensional programs:

q1)Write a program to enter any four elements and display that.
                                                                                                                                              solution

q2) Write a program to enter some elements and display that in opposite order.
                                                                                                                                              solution

q3).Write a program to get sum of numbers out of 'n' numbers entered by you.
                                                                                                                                              solution


q4).Write a program to display all numbers which are stored in even positioned cell of array.Let there are 'n' numbers.
                                                                                                                                              solution

q5)Write a program to display all numbers which are stored in odd positioned cell of array.Let there are 'n' numbers.
                                                                                                                                              solution

q6)Write a program to delete an element stored in an array. Let there are 'n' numbers..
                                                                                                                                              solution

q7)Write a program to swap any two values stored in array.Let there are 'n' numbers.
                                                                                                                                              solution

q8)Write a program to get maximum and minimum value among 'n' values stored in array.
                                                                                                                                              solution

q9)Write a program to store any 'n' elements and display those which are >15.
                                                                                                                                             solution
q10)Write a program to get sum of all elements of two one dimensional arrays.
                                                                                                                                              solution
q11)Write a program to get difference of all elements of two one-dimensional elements.                                                                                                                                                                                   solution
q12)Write a program to count total positive elements among 'n' elements.
                                                                                                                                              solution
q13)Write a program to sort (ascending order) elements stored in array.
                                                                                                                                              solution
q14)Write a program to sort (descending order) elements stored in array.
                                                                                                                                               solution

q15) WAP to enter salary of 'n' number of employees. Now count number of employees getting salary in range:
            a) less than 5000
           b) >=5000 and < 10000
           c)  >10000     
                                                                                                                                     solution
q16)WAP to search an element stored in an array.
                                                                                                                                                                                                                                                                         solution
q17) Write a program to show initialization of element in an array.
                                                                                                                                      solution
q18) Write a program to know repetition of elements stored in array.
                                                                                                                                      solution
multidimensional array programs:-
q19) WAP to input values for matrix of order 2x2 and display that.
                                                                                                                                  solution
q20)WAP to initialize elements of an array of size 2x2. Then display that.
                                                                                                                                  solution
q21) WAP to get sum of elements of an array of order 'mxn'.
                                                                                                                                  solution
q22) WAP to get sub-matrix of a matrix of order 'mxn'.
                                                                                                                                   solution
q23)WAP to get sum of elements of first row of a matrix of order 'mxn'.
                                                                                                                                   solution
q24)WAP to transpose  a matrix of order mxn.
                                                                                                                                   solution
q25)WAP to get sum of diagonal elements of a matrix of order mxn.

                                                                                                                                  solution

q26)WAP to print upper triangular matrix  of order mxn.
                                                                                                                                 solution
q27) WAP to print lower triangular matrix  of order mxn.
                                                                                                                                  solution

Here are collection of programs using loop. You have here programs written in while,do..while and for loop separately. Some are done using all loops as a sample to make you understandable. Then programs preceded by them can be written in same manner.Some programs are with 'if structure' depending upon requirements by question.

program to convert decimal number into Hexadecimal.

//program to convert decimal number into Hexadecimal.
#include<stdio.h>
#include<conio.h>
void main()
{
  long int decimal_number;
  printf("Enter any decimal number: ");
  scanf("%ld",&decimal_number);
  printf("Equivalent hexadecimal number is: %X",decimal_number);
getch();
}


logics in mind:

if decimal number is 19 (base 10) then
hexadecimal number can be obtained using simply its format specifier %x.
       note:

we can also write same program using ascii value and array.
the program goes like,
#include<stdio.h>
void main()
{
    long int decimalNumber,remainder,quotient;
    int i=1,j,temp;
    char hexadecimalNumber[100];                    //array is used to store equivalent hexadecimal number
    printf("Enter any decimal number: ");
    scanf("%ld",&decimalNumber);
    quotient = decimalNumber;
    while(quotient!=0){
         temp = quotient % 16;
      //To convert integer into character
      if( temp < 10)
           temp =temp + 48;          //48 is added to temp to convert number into character, look ascii table
      else
         temp = temp + 55;                                //ascii value is used as a character after adding to number

      hexadecimalNumber[i++]= temp;
      quotient = quotient / 16;
  }
    printf("Equivalent hexadecimal value of decimal number %d: ",decimalNumber);
    for(j = i -1 ;j> 0;j--)
      printf("%c",hexadecimalNumber[j]);

}

                                        source:
                                         http://www.cquestions.com

program to convert decimal number into binary.

//program to convert decimal number into binary.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int k=1,m=0,n,rem,binary=0;
printf("enter decimal value/number of 'n'\n");
scanf("%d",&n);
while(n!=0)
   {
      rem=n%2;
      binary=binary+rem*pow(10,m);
      n=n/2;
      m++;
   }
printf("binary is=%d\n",binary);
getch();
}



logics in mind:

if decimal number is 9 (base 10) then
binary=dividing 9  by 2 and getting remainder.It is 1001. 
making its formula in program
1001=1000+000+00+1
         =1*103+0*102+0*101+1*100
       note:

it does not work for long values(more than 30 04 28). It can, if you declare variables as long. 

program to convert binary no. into decimal number system

//program to convert binary no. into decimal number system
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int k=1,m=0,n,rem,decimal=0;
printf("enter binary value/number of 'n'\n");
scanf("%d",&n);
while(n!=0)
   {
      rem=n%10;
      decimal=decimal+rem*pow(2,m);
      n=n/10;
      m++;
   }
printf("decimal is=%d\n",decimal);
getch();
}

logics in mind:

if binary number is 101 (base 2) then
decimal=1x22+0x21+1x20
making its formlua in program

note:
it does not work for long values. It can, if you declare variables as long. 

program to print/display 11111,1111,111,11,1 to nth term.

//program to print/display ...11111,1111,111,11,1 to nth term.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int m=1,n,number,denom;
printf("enter value of 'n' as a number of terms \n");
scanf("%d",&n);
printf("now enter number having %d digits(1)\n",n)
scanf("%d",&number);while(n>=m)
   {
            printf("%d\n",number);
      denom=pow(10,n-1);      
         number=number/denom;
      
      n--;
   }
getch();
}
..................................
logics in mind:

if n= 6(It means a number with 6 ones i.e. 111111)
111111,11111,1111,111,...
can be shown as
first 11111
second dividing above number by 10th power of entered number -1
as the second iteration goes , it has value with 1 less digit.
it continues until the value lasts to 1.