#include <stdio.h>
#include <windows.h>
#include <conio.h>
#define SIZE 100
void main()
{
char ch;
int size=0, a[SIZE], i=0, b=0, temp=0, x=0, w, largest=0, largest2=0, q;
int c;
do{
printf("Enter how many numbers you want to input: ");
scanf("%d",&size);
printf("Enter %d numbers you want to enter: ", size);
for(i=0;i<size;i++){
scanf("%d", &a[i]);
}
printf("\n");
printf("\n");
printf("This are the numbers u entered: ");
for(b=0;b<size;++b){
printf(" %d", a[b]);
}
//largest
for(w=0;w<size;w++){
if(largest<a[w])
largest=a[w];
}
printf("\nThis is the largest number you entered: %d", largest);
//2nd largest
for(q=0;q<size;q++){
if(largest>a[q]){
if(largest2<a[q]){
largest2=a[q];
}}
}
printf("\nThis is the second largest number you entered: %d", largest2);
//sorted
for(i=0;i<size;i++){
for(b=0;b<(size-(i+1));b++){
if (a[b]>a[b+1]){
temp=a[b];
a[b]=a[b+1];
a[b+1]=temp;
}}}
printf("\nThis are the sorted numbers: ");
for(x=0;x<size;++x){
printf(" %d", a[x]);
}
printf("\n");
printf("\nRun again?(y/n)");
ch = getch();
if(ch=='y'||ch=='Y'){
c=1;
system("cls");
}
else{
c=0;
}
fflush(stdin);
}while(c==1);
}
About this blog
These codes here are just based on my own knowledge learned from my IT subjects. I know there are more ways that this draft codes can be enhance, so..
Please feel free to comment & suggest.. Suggest Codes which makes my existing codes simpler.. Thanks!
Archives
Categories
Making Life Simple w/ Programming
Links
- w3schools.com
- Java & Textpad Setup Guide 2
- Java & Textpad Setup Guide
- ASCII Alphabet Characters
- File Handling - Forum
- File Handling - Tutorial 0.1
- File Handling - Tutorial 0.2
- Bin-Dec Conversion - Forum
- Use of getch(), getche(), & getchar()
- The C Book
- SEO
- Common C programming errors
- Tutorial - Array Functions
- August Council Tutorial - c
- C language tutorials
- cprogramminglanuage.net
0 comments