Post your C/C++ Programs Here

Status
Not open for further replies.

arshetty

Right off the assembly line
Re: Post ur C/C++ Programs Here

what i nice program i see!!!1
it is realy helpful for student who learn c or c++
a small program is there i.e
how to swap the value of two variable without using 3rd variable
logic:int a,b;
a=10;
b=11;
a=a+b
b=a-b;
a=a-b;



 

QwertyManiac

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

Request for renaming thread to "Swapping two variables - The most impractically important thing every coder worth his NaCl must know."
 

nvidia

-----ATi-----
Re: Post ur C/C++ Programs Here

I was writing a program to solve problem #3 in Project Euler in C.
But it says that the constant "600851475143" is too long! Is there anyway to overcome this?
 

nvidia

-----ATi-----
Re: Post ur C/C++ Programs Here

^I know there are alternative languages. But i wanted to know if there is any way to overcome this error in C.
 

QwertyManiac

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

^I know there are alternative languages. But i wanted to know if there is any way to overcome this error in C.
aditya.shevade mentioned the GMP library, you could use that of course. GMP is short for GNU MultiPrecision library. Look for guides and other help with it here: *gmplib.org/. Works with C/C++.

There is only so-much you can do with vanilla C, unless of course you decide to write your own big-number stuff, that GMP provides you with. :)

@mehulved - Common salt today, maybe a language tomorrow. Ah I must have "lost count". :p
 

Sykora

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

nvidia: Use the unsigned long long data type. Should be enough for your purposes. If you have 64 bit libs, and can program on it, all the better.

gmp would be the best way to go, but I hate using it without the oo goodness I get in the c++ wrappers.
 

nvidia

-----ATi-----
Re: Post ur C/C++ Programs Here

^^If i use "unsigned long long" then whats the character that i should use in the input and the output stings? Like
Code:
scanf("%(what?)",&variable);
Or suggest me a C compiler which can support large values.
 

QwertyManiac

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

%lld or %llu should work fine.

Supporting large values is not what a compiler can provide, heh. We've said the same over and over again, GNU MP BigNum is your answer. If you don't want to listen why ask again? :)
 

Sykora

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

nvidia:

The size of vaiues you can work with depends on your c libs, not your compiler. Use long long, but if that's not enough, there really is no avoiding gmp (if you want to stick with c, that is).
 

aditya.shevade

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

That is not entirely true Sykora and QwertyM right? I mean, if he is using 16 bit compiler (the borland one that comes with turboC (the one that sucks)) then the values will be small....
 

santhoshkr

Right off the assembly line
Need help in C++ programming

Dear All,

I am working on DTV application developement project, the requirement says that, 1. For Photo application , I need to extract the metadata(exif format used in digital cameras) using C++ code.
2. For Music and Video application, I need to extract the metadata(ID3 format) in MP3 files using C++ code.

Could you please suggest me the code or library which will help in getiing my work done.

Thanking You

With You Always
HappyKumar:)
 

shady_inc

Pee into the Wind...
Re: Post ur C/C++ Programs Here

Started to learn user defined data types and operator overloading in C++.You can almost create your own new language using these.Now I understand C++'s superiority over other languages. ! :p
 

sameissa

Right off the assembly line
Re: Post ur C/C++ Programs Here

Hello
I made the following program with C language - but I do not know how to fix the error when the user enters characters instead of numbers;
For Example:
the values entered by the user must be numbers only not characters - and if he type character the program should give him error message says that " please enter numbers only"
how to do this.
appreciate any help ?



#include <stdio.h>
#include <conio.h>

float fs;
float t;
float f;
float q;
float c;
int x,i,a;

int S,M,H;

int main()

{
char Ans;

for (i=1;i<=5;i=i+a)
{
i--;

printf(" -------------------------------------------------------------------------- \n");
printf(" \n");
printf(" >> Welcome To Audio System >> \n");
printf(" \n");
printf(" -------------------------------------------------------------------------- \n");
printf(" \n");
printf(" Please Enter: \n");
printf(" \n");
printf(" [1] To calculate File Size \n");
printf(" \n");
printf(" [2] To calculate Time \n");
printf(" \n");
printf(" [3] To calculate Frequnecy \n");
printf(" \n");
printf(" [4] To calculate Quantization \n");
printf(" \n");
printf(" [5] To calculate Channels \n");
printf(" \n");
printf(" -------------------------------------------------------------------------- \n");
printf(" \n");
scanf("%d",&x);

if (x==1)
{
printf(" Please Enter Time \n Seconds\n ");
scanf("%d",&S);
printf(" \n");
printf(" Minutes\n ");
scanf("%d",&M);
printf(" \n");
printf(" Hours\n ");
scanf("%d",&H);
printf(" \n");
t=S+(M*60)+(H*60*60);
printf(" Please Enter Frequnecy \n ");
scanf("%f",&f);
printf(" \n");
printf(" Please Enter Quantization \n ");
scanf("%f",&q);
printf(" \n");
printf(" Please Enter Channels \n ");
scanf("%f",&c);
printf(" \n");
fs=t*(f*1000)*q*c;
fs=fs/8/1024/1024;
printf(" \n");
printf(" -------------------------------------------------------------------------- \n");
printf(" \n");
printf(" The file size is %f MB \n",fs);
printf(" \n");
printf(" -------------------------------------------------------------------------- \n");
}
else if (x==2)
{ printf(" Please Enter \n File Size \n ");
scanf("%f",&fs);
printf(" Please Enter Frequnecy \n ");
scanf("%f",&f);
printf(" Please Enter Quantization \n ");
scanf("%f",&q);
printf(" Please Enter Channels \n ");
scanf("%f",&c);
t= fs/(f*q*c);
printf(" -------------------------------------------------------------------------- \n");
printf(" \n");
printf(" The time is %f s \n",t);
printf(" \n");
printf(" -------------------------------------------------------------------------- \n");
}
else if (x==3)
{ printf(" Please Enter File Size \n ");
scanf("%f",&fs);
printf(" Please Enter Time \n Seconds\n ");
scanf("%d",&S);
printf(" Minutes\n ");
scanf("%d",&M);
printf(" Hours\n ");
scanf("%d",&H);
t=S+(M*60)+(H*60*60);
printf(" Please Enter Quantization \n ");
scanf("%f",&q);
printf(" Please Enter Channels \n ");
scanf("%f",&c);
f= (fs/(t*q*c))/1000;
printf(" -------------------------------------------------------------------------- \n");
printf(" \n");
printf(" The Frequnecy is %f KHz \n",f);
printf(" \n");
printf(" -------------------------------------------------------------------------- \n");
}
else if (x==4)
{ printf(" Please Enter \n File Size \n ");
scanf("%f",&fs);
printf(" Please Enter Time \n Seconds\n ");
scanf("%d",&S);
printf(" Minutes\n ");
scanf("%d",&M);
printf(" Hours\n ");
scanf("%d",&H);
t=S+(M*60)+(H*60*60);
printf(" Please Enter Frequnecy \n ");
scanf("%f",&f);
printf(" Please Enter Channels \n ");
scanf("%f",&c);
q= fs/(t*f*c);
printf(" -------------------------------------------------------------------------- \n");
printf(" \n");
printf(" The Quantization is %f \n",q);
printf(" \n");
printf(" -------------------------------------------------------------------------- \n");
}

else if (x==5)
{
printf(" Please Enter \n File Size \n ");
scanf("%f",&fs);
printf(" Please Enter Time \n Seconds\n ");
scanf("%d",&S);
printf(" Minutes\n ");
scanf("%d",&M);
printf(" Hours\n ");
scanf("%d",&H);
t=S+(M*60)+(H*60*60);
printf(" Please Enter Frequnecy \n ");
scanf("%f",&f);
printf(" Please Enter Quantization \n ");
scanf("%f",&q);
c= fs/(t*f*q);
printf(" -------------------------------------------------------------------------- \n");
printf(" \n");
printf(" The Channels is %f \n",c);
printf(" \n");
printf(" -------------------------------------------------------------------------- \n");
}
else
{

printf(" -------------------------------------------------------------------------- \n");
printf(" \n");
printf("\t\t\t\t \n Sorry you have typed wrong input\n \n ");
printf("\t\t\t\t \n Please Enter Correct Number from [1] TO [5] \n\n ");
printf(" \n");
printf(" -------------------------------------------------------------------------- \n");

}

do
{
printf ("\t\t Please TYPE 'y' To Exit To The Main Menu ");
scanf ("%c", &Ans);

if(Ans == 'n' || Ans =='N')
printf("\t\t \n Could you Please Leave Me Now...\n\n", Ans);
else if(Ans == 'y' || Ans == 'Y')
break;
else
printf ( " \n\n");
}
while(Ans != 'y' || Ans != 'Y');

printf(" \n");

printf(" -------------------------------------------------------------------------- \n");
printf(" \n");
printf ( "\t\t >> ...Thank YOU For Using OUR Audio System... >> \n\n");
printf(" \n");
printf(" -------------------------------------------------------------------------- \n");
printf(" \n");
printf ( "\t\t To Exit To The Main Menu Press Any Key to Exit...");
printf(" \n");
printf(" -------------------------------------------------------------------------- \n");
getch();
}
}


thanks

enashre@yahoo.com
 
Last edited:
Status
Not open for further replies.
Top Bottom