| | |
beginner"problem in arrays help me in codes"
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2004
Posts: 2
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Nov 2004
Posts: 68
Reputation:
Solved Threads: 1
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
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
![]() |
Similar Threads
- Slight Problem with arrays. (Java)
- How to call the function including arrays of structure in main.c? (C)
- Newbie Problem: Arrays (C++)
- system("pause"); (C++)
- beginner compile problem (Assembly)
- Array problem (C)
Other Threads in the C Forum
- Previous Thread: help with codes
- Next Thread: repost, function alogorithm problem
Views: 2681 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createprocess() database directory drawing dynamic execv feet fgets file floatingpointvalidation fork framework function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes radix read recursion recv recvblocked reversing segmentationfault single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi






