Post your C/C++ Programs Here

Status
Not open for further replies.
OP
Gigacore

Gigacore

Dreamweaver
Re: Post ur C/C++ Programs Here

A C program to find the maximum and minimum elements in an array having N elements

Code:
#include <stdio.h>
main()
{
	int a [100]; /* Array Declaration */
	int i,n,max,mini;
	printf("Enter number of elements in the array");
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	max=a[0];
	mini=a[0];
	for(i=1;i<n;i++)
	{
		if(max<a[i])max=a[i];
		if(mini>a[i])mini=a[i];
	}
	printf("\nMaximum element in the array is %d",max);
	printf("\nMinimum element in the array is %d",mini);
return 0;
}
 

The_Devil_Himself

die blizzard die! D3?
Re: Post ur C/C++ Programs Here

Good one gigacore.But it exits without showing result in turbo c++.BTW why do you hate getch() to much?
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

Code:
#include <stdio.h>
[B]#include<conio.h>[/B]
void main()
{
	int a [100]; /* Array Declaration */
	int i,n,max,mini;
	printf("Enter number of elements in the array");
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	max=a[0];
	mini=a[0];
	for(i=1;i<n;i++)
	{
		if(max<a[i])max=a[i];
		if(mini>a[i])mini=a[i];
	}
	printf("\nMaximum element in the array is %d",max);
	printf("\nMinimum element in the array is %d",mini);
[B]getch();[/B]
}

This is the 'Turbo C' version of your program, you need to include conio.h and use getch() at the LAST line.
 

The_Devil_Himself

die blizzard die! D3?
Re: Post ur C/C++ Programs Here

Yep you need to include conio.h for getch and clrscr to work.Try out man both getch and clrscr are very handy.
 

aditya.shevade

Console Junkie
Re: Post ur C/C++ Programs Here

The_Devil_Himself said:
Yep you need to include conio.h for getch and clrscr to work.Try out man both getch and clrscr are very handy.

Hmm.... maybe handy, but they cause the program to become non-portable. (At least, entire portability is not achieved). You cannot compile those programs on machines not running borland compiler.

Aditya
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

Yeah and they both are unavailable in Standard C/C++, so it's always suggested to stay away from them. Why don't you run your programs via CMD instead? That'll show the output and still stay alive. :)
 
OP
Gigacore

Gigacore

Dreamweaver
Re: Post ur C/C++ Programs Here

@ QWERTY... its working thanks a lot.....

And thanks for other guys who involved in help :)
 

New

Padawan
Re: Post ur C/C++ Programs Here

U peoples are doing good work.
Buy the way can anyone send some programs on pointers , strings and structurs?
I have internal next week.before that i have to prepare for these three chapters..
Please...
Thanks in advance..
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

Heh I can read that but just in case he wants something specific.

A program combining all 3 he's asked is already present here. :)
 

shyamno

Ambassador of Buzz
Re: Post ur C/C++ Programs Here

How can we write a program (any program) without writing anything in main() ???
 

Sykora

I see right through you.
Re: Post ur C/C++ Programs Here

Evidently it is possible in C++. I found about it only recently. It seems that static constructors execute before any other function in a program, so put everything in a static constructor and create a global object. Leave main() out.
 

shyamno

Ambassador of Buzz
Re: Post ur C/C++ Programs Here

Can we write this ????

#define main() main(){printf("Hello World\n");}

main()
 

New

Padawan
Re: Post ur C/C++ Programs Here

Friends i need programs in C on pointers ,strings and structures.. two days left for my internals:mad: i don't want to read any books..instead i want some programs from you peoples..
one question.
What is global declaration?give one example?
If anyone has good notes on these three chapters please send.
THANKS IN ADVANCE..
 
Status
Not open for further replies.
Top Bottom