Tuesday, 17 December 2013

Write a program which reads a set of integers into an integer array and then prints those numbers which occurs only once

#include<stdio.h> int main() { int i, n, a[10], j, c; printf("Enter a number\n"); scanf("%d",&n); printf("Enter %d number\n",n); for(i=0;i<n;i++) {scanf("%d",&a[i]);} for(i=0;i<n;i++) /*To traverse array element by element */ { c=0; /* counter is initialized to 0 */ for(j=0;j<n;j++) { /* comparing ith element with all other elements */ If(a[i]==a[j]) c++; } if(c==1) printf("%d\n",a[i]); } return 0; }

No comments:

Post a Comment