Posts

Showing posts from October, 2010

C Program To Calculate The Of N Numbers Using Array

♣ Try it Out :: #include<stdio.h> #include<conio.h> main() { int Num[101], Sum = 0, TotalNum, i; printf("How many numbers you wish to add: "); scanf("%d", &TotalNum); printf("Enter %d Integers: ", TotalNum); for(i=0; i<TotalNum; i++) scanf("%d", &Num[i]); for(i=0; i<TotalNum; i++) Sum = Sum + Num[i]; printf("\nSum of entered numbers is = %d\n", Sum); getch(); return(0); } ♣ Output :: How many numbers you wish to add: 5 Enter 5 Integers: 125 10 25 30 450 Sum of entered numbers is = 640 ♣ Downloads :: Download source code Download executable file

C Program To Reverse An Array Using For Loop

♣ Try it Out :: #include<stdio.h> #include<conio.h> main() { int Arr[101], Num, i; printf("How many numbers you wish to input in array: "); scanf("%d", &Num); printf("Enter %d Integers:\n", Num); for(i=0; i<Num; i++) scanf("%d", &Arr[i]); printf("\nReverse Array is:\n"); for(i=Num-1; i>=0; i--) printf("%d ", Arr[i]); getch(); return(0); } ♣ Output :: How many numbers you wish to input in array: 5 Enter 5 Integers: 8 4 2 0 3 Reverse Array is: 3 0 2 4 8 ♣ Downloads :: Download source code Download executable file

C Program To Search A Number In Array

♣ Try it Out :: #include<stdio.h> #include<conio.h> main() { int Array[] = {9, 5, 2, 10, 6, 1}; int Size = sizeof(Array) / sizeof(int); int Search, i; printf("Entered array is: \n"); for(i=0; i<Size; i++) printf("%d ", Array[i]); printf("\nEnter the number to search: "); scanf("%d", &Search); for(i=0; i<Size; i++) if(Array[i] == Search) break; if(i == Size) printf("%d is not present in array. \n", Search); else printf("%d is present at location %d. \n", Search, i+1); getch(); return(0); } ♣ Output :: Entered array is: 9 5 2 10 6 1 Enter the number to search: 6 6 is present at location 5. ♣ Downloads :: Download source code Download executable file

C Program To Find Maximum Number In Array

♣ Try it Out :: #include<stdio.h> #include<conio.h> main() { int Array[100], MaxNum, Size, pos = 1, i; printf("How many numbers you wish to input in array: "); scanf("%d", &Size); printf("Enter %d integers: ", Size); for(i=0; i<Size; i++) scanf("%d", &Array[i]); MaxNum = Array[0]; for(i=1; i<Size; i++) { if(Array[i] > MaxNum) { MaxNum = Array[i]; pos = i + 1; } } printf("\nMaximum number is %d and it's position is %d.\n", MaxNum, pos); getch(); return(0); } ♣ Output :: How many numbers you wish to input in array: 5 Enter 5 integers: 40 25 30 125 5 Maximum number is 125 and it's position is 4. ♣ Downloads :: Download source code Download executable file

C Program To Find Minimum Number In Array

♣ Try it Out :: #include<stdio.h> #include<conio.h> main() { int Array[100], MinNum, Size, pos = 1, i; printf("How many numbers you wish to input in array: "); scanf("%d", &Size); printf("Enter %d integers: ", Size); for(i=0; i<Size; i++) scanf("%d", &Array[i]); MinNum = Array[0]; for(i=1; i<Size; i++) { if(Array[i] < MinNum) { MinNum = Array[i]; pos = i + 1; } } printf("\nMinimum number is %d and it's position is %d.\n", MinNum, pos); getch(); return(0); } ♣ Output :: How many numbers you wish to input in array: 5 Enter 5 integers: 122 10 55 36 21 Minimum number is 10 and it's position is 2. ♣ Downloads :: Download source code Download executable file

C Program To Insert An Element In An Array

♣ Try it Out :: #include<stdio.h> #include<conio.h> main() { int Arr[101], Value, Size, i, pos; printf("How many numbers you wish to input in array: "); scanf("%d", &Size); printf("Enter %d integers: \n", Size); for(i=0; i<Size; i++) scanf("%d", &Arr[i]); printf("\nEnter position where you wish to insert an element: "); scanf("%d", &pos); printf("Enter the value to insert: "); scanf("%d", &Value); for(i=Size-1; i>=pos-1; i--) Arr[i+1] = Arr[i]; Arr[pos-1] = Value; printf("\nResultant array is:\n"); for(i=0; i<=Size; i++) printf("%d ", Arr[i]); getch(); return(0); } ♣ Output :: How many numbers you wish to input in array: 5 Enter 5 integers: 4 2 3 9 7 Enter position where you wish to insert an element: 3 Enter the value to insert: 6 Resultant array is: 4

C Program To Delete An Element From An Array

♣ Try it Out :: #include<stdio.h> #include<conio.h> main() { int Arr[] = {8, 6, 2, 3, 1, 0, 4, 5}; int Size = sizeof(Arr) / sizeof(int); int i, pos, Value; printf("Entered elements in array are:\n"); for(i=0; i<Size; i++) printf("%d ", Arr[i]); printf("\nEnter position where you wish to delete an element: "); scanf("%d", &pos); if(pos >= Size+1) printf("Deletion not possible.\n"); else { for(i=pos-1; i<Size-1; i++) Arr[i] = Arr[i+1]; printf("\nResultant array is:\n"); for(i=0; i<Size-1; i++) printf("%d ", Arr[i]); } getch(); return(0); } ♣ Output :: Entered elements in array are: 8 6 2 3 1 0 4 5 Enter position where you wish to delete an element: 6 Resultant array is: 8 6 2 3 1 4 5 ♣ Downloads :: Download source code Download executable file