Showing posts with label array. Show all posts
Showing posts with label array. Show all posts

Friday, April 11, 2014

Count reapetation number of unique values of an array Sort according higher occurance of values


/* A program to calculate no. of uniqe values of an array
implemented logic can be useful anywhere-
where we required count no. of same rate books in a library
e.g. 250$: 3books 300$: 4books 34$: 5books
Date: 9/3/2013 10:05pm
Author: Mangilal Saraswat */

#include<stdio.h>
#include<conio.h>
void main()
{
 clrscr();
 int i,j,k,done,a[10],b[10],c[10];
 i=0; j=0; k=0; done=0;

 printf("Enter array:
");

 for(i=0;i<10;i++)
 {
  scanf("%d",&a[i]);
  c[i]=0;
 }

 for(i=0; i<10; i++)
 {
  for(j=0;j<k;j++)
  {
   if(a[i]==b[j])
   {
    b[j]=a[i];
    c[j]=c[j]+1;
    done=1;
   }
  }
  if(done==0)
  {
   b[k]=a[i];
   c[k]=c[k]+1;
   k=k+1;
  }
  done=0;
 }

 for(j=0;j<k;j++)
 {
  printf("value: %d ",b[j]);
  printf("times: %d
",c[j]);

 }
 getch();
}

Read More..

Friday, April 4, 2014

Reverse array

Q. Write a c program to accept n elements from user and reverse all elements.


Ans.

/*c program for reverse an array*/
#include<stdio.h>
#include<conio.h>
#define S 50
int main()
{
 int i,num,mid;
 float arr[S],tmp;
 printf("Ener total number of element in array : ");
 scanf("%d", &num);
 for(i=0; i<num; i++)
 {
   printf("Enter %d element : ",i+1);
   scanf("%f", &arr[i]);
 }
 mid = num/2;
 for(i=0; i<mid; i++)
 {
   /*swapping*/
   tmp = arr[i];
   arr[i]= arr[num-1-i];
   arr[num-1-i] = tmp;
 }
 printf("
-- Array in reverse order --

"
);

 for(i=0; i<num; i++)
    printf(" %.2f
"
,arr[i]);

 getch();
 return 0;
}

/************Output************/


Output of accept n elements from user and reverse all elements C program
Screen shot for reverse array C program

Related program:
  1. Reverse array using simple C program
Read More..
 
Blog Information - Powered By Blogger