Monday, May 24, 2010

Can anyone convert the below c program to c++ program or just tell how to find the biggest no among the n no?

#include%26lt;stdio.h%26gt;


int max(int[],int,int);


main()


{


int a[100],i,n,temp,big;


clrscr();


printf("enter how many numbers:");


scanf("%d",%26amp;n);


printf("enter the element");


for(i=0;i%26lt;n;i++)


scanf("%d",%26amp;a[i]);


big=a[0];


printf("the biggest no is",biggest(a,n,big));


getch


}


int max(int a[],int n,int big)


{


if(n==0)


return big;


else


n--;


if(a[n]%26gt;big)


big=a[n];


return (max(a,n,big));


}


reply soon only in c++ program. Thank u

Can anyone convert the below c program to c++ program or just tell how to find the biggest no among the n no?
Save as your file with extension CPP and replace header file stdio.h with iostream.h and also add conio.h for clrscr() and getch().





now replace all scanf() with cin%26gt;%26gt;num and you have no need to specify format characters(%d or %c) and also printf () with cout%26lt;%26lt; num without any format specfiers..
Reply:replace stdio by iostream in header


replace scanf("%d",%26amp;n) by cin%26gt;%26gt;n and so on


replace printf("...................",d,g,h) by cout%26lt;%26lt;".........."%26lt;%26lt;d%26lt;%26lt;g%26lt;%26lt;h; and so on


it will work
Reply:that also works in C++ no need to convert except for the libraries i think getch() is in stdlib.h and also use cin and cout instead of printf and scanf in the ipstream.h
Reply:This sounds like homework. What is the class?

flowers on line

No comments:

Post a Comment