943,969 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3207
  • C RSS
Nov 19th, 2004
0

beginner"problem in arrays help me in codes"

Expand Post »
undefined
hi,
i m naya.i m student of telecommunicatin engineering.i have a lot problems in "C PROGRAMMING".plz tell me the codes to find max,min values....to print factorial of a number...how copy an array to other.....to print tables of numbers....n how to swaps in array..
plz they all codes should be in arrays...plz help me
in 21 nov i will give exam in my uni. of "ARRAYS IN C"
I SHALL BE VERY TO U.....
BYE
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
naya is offline Offline
2 posts
since Nov 2004
Nov 19th, 2004
0

Re: beginner"problem in arrays help me in codes"

I have a better idea. You prove that you've tried to solve these problems on your own, and we'll help you with any errors. No one is going to do your homework for you.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 19th, 2004
-1

Re: beginner"problem in arrays help me in codes"

oh sure !! i can help you out.Here are the codes
1. Finding Maximum and minimum values in a array

# include<stdio.h>
# define MAX 10
void main()
{ int a[MAX],i,mini,maxi;
for(i=0;i<MAX;i++)
{ printf("Enter Any number : ");
scanf("%d",&a[i]);
}
mini=a[0];
maxi[0];
for(i=1;i<MAX;i++)
{ if(a[i]>max)
maxi = a[i];
if(a[i]<min)
mini = a[i];
}
printf("The minimum and maximum no in the given array is %d and %d",mini,maxi);
getch();
}

2. Sorting an array.
There are many techniques to sort a given array .One of it is given below.This code sorts the array in an ascending order , if u want to sort in descending order just change the sign from ">" to "<" in the code.rest all wil remain as it is .

# include<stdio.h>
# define MAX 10
void main()
{ int a[MAX],i,j,temp;
for(i=0;i<MAX;i++)
{ printf("Enter Any number : ");
scanf("%d",&a[i]);
}
for(i=0;i<MAX;i++)
{ for(j=i+1;j<MAX;j++)
{ if(a[i]>a[j])
{ temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("The sorted Array is : \n");
for(i=0;i<MAX;i++)
{ printf("%d\n",a[i]);
}
getch();
}

3. Factorial of a given numbers , i m taking an example that an array consist of 10 elements and i have to find the factorial of each number ,and store it in seperate array and finally printing printing the array.

# include<stdio.h>
# include<conio.h>
# define MAX 10
void main()
{ long int a[MAX],fact[MAX],i,j;
int pro;
for(i=0;i<MAX;i++)
{ printf("Enter Any number : ");
scanf("%ld",&a[i]);
}
for(i=0;i<MAX;i++)
{ pro=1;
for(j=1;j<=a[i];j++)
{ pro *=j;
}
fact[i]=pro;
}
for(i=0;i<MAX;i++)
{ printf("\nFactorial of %d : ",a[i]);
printf("%ld\n",fact[i]);
}
getch();
}
I hope all these codes will be helpful to you.All the best for your Exams .

cheers,
Harsh chandra
Reputation Points: 7
Solved Threads: 1
Junior Poster in Training
harshchandra is offline Offline
68 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: help with codes
Next Thread in C Forum Timeline: repost, function alogorithm problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC