main()
{
int i=3;
float j=3.5;
printf("%f",i);
printf("%d",j);
}
Explain the following program in C.?
Using %f notation we print a float. Here i is a integer but printing using %f notation the it will print 3.00000
But %d notation is for integer printing so if we print a float of value 3.5 then it will print 3 only
%f -- float printing
%d -- decimal printing
Reply:Others have spotted the mistakes; there, but if this is just an exam question and they are making 'mistakes' purposely the traced output should be 0234327823784 or some weirdly long garbage number.
Reply:A simple program which prints two numbers - an integer (3) and a float (3.5)
1. The first line defines the program
2. The 3-rd and 4-th lines define the type of the numbers (3 is integer, 3.5 is float) and assigns them to variables - i and j
3. The "printf" command is used to print the numbers on the screen. "%f" means that Decimal floating point will be used to format the number, "%d" means Signed decimal integer.
So the output of the program will be the numbers 3 and 3.5
I see a mistake here. Wrong formatting is used for the numbers. Choose one of the following:
1.) printf("%d",i);
printf(%f",j);
-OR-
2.) float i=3.5;
int j=3;
Monday, May 24, 2010
Answer this trick question in C language...find the output of this...?
#include%26lt;string.h%26gt;
main()
{
char str1[] = "Infosys";
char str2[] = "Infosys";
if(str1==str2)
printf("\n Equal");
else
printf("\n UnEqual");
}
Answer this trick question in C language...find the output of this...?
prints "UnEqual"
the == function will actually be checking if the strings are at the same memory location. To compare strings, you need to use strcmp() and check that the return value is zero.
main()
{
char str1[] = "Infosys";
char str2[] = "Infosys";
if(str1==str2)
printf("\n Equal");
else
printf("\n UnEqual");
}
Answer this trick question in C language...find the output of this...?
prints "UnEqual"
the == function will actually be checking if the strings are at the same memory location. To compare strings, you need to use strcmp() and check that the return value is zero.
Please help me fix this c program---thanks?
okey...this program works properly,, all i need is to organize my results... let it display. the compound interest with the rate being __is: and so on.. please help.
#include %26lt;stdio.h%26gt;
#include %26lt;math.h%26gt;
int main(void)
{
double amount;
double principal=1000.0;
double rate= .05;
int year;
int six_percent;
printf("%4s%21s\n", "year", "Amount on deposit");
for(year=1 ;year%26lt;=10 ; year++)
for(rate=.05; rate%26lt;=0.10; rate+=.01)
{
amount=principal * pow(1.0 +rate ,year);
printf("%4d%21.2f\n"year,amount);
}
}
the program needs to display the compound interest using 5%,6%,7%,8%,9%,10% as the rate. the questions specifies that i must use a for loop..
Please help me fix this c program---thanks?
dude why dont you just not set the rate standards and have it loop right then in one of you printf statements ask the user t enter the following rates
such as 5 6 7 8 9 and 10
Reply:I don't know if it's the only problem, but you need a comma in the printf statement between the second " and the year variable.
#include %26lt;stdio.h%26gt;
#include %26lt;math.h%26gt;
int main(void)
{
double amount;
double principal=1000.0;
double rate= .05;
int year;
int six_percent;
printf("%4s%21s\n", "year", "Amount on deposit");
for(year=1 ;year%26lt;=10 ; year++)
for(rate=.05; rate%26lt;=0.10; rate+=.01)
{
amount=principal * pow(1.0 +rate ,year);
printf("%4d%21.2f\n"year,amount);
}
}
the program needs to display the compound interest using 5%,6%,7%,8%,9%,10% as the rate. the questions specifies that i must use a for loop..
Please help me fix this c program---thanks?
dude why dont you just not set the rate standards and have it loop right then in one of you printf statements ask the user t enter the following rates
such as 5 6 7 8 9 and 10
Reply:I don't know if it's the only problem, but you need a comma in the printf statement between the second " and the year variable.
De Morgans Law in C++?
I am having some problems trying to compile this program can anyone help me out?
#include %26lt;iostream%26gt;
using std::cin;
int main()
{
// input range to scan values
cin %26gt;%26gt; lowerx;
cin %26gt;%26gt; upperx;
// loop over all combinations of x and y
for (int x = lowerx; x %26lt; upperx; x++)
{
for (int y = lowery; y %26lt; uppery; y++)
{
if (!(x%26lt;5)%26amp;%26amp;!(y%26gt;=7) != !((x%26lt;5)||(y%26gt;=7))) // test equivalence
{
printf("Expressions are not equivalent. x = %d, y = %d", x, y);
return;
}
}
}
printf("Expressions are equivalent over the specified range");
return;
De Morgans Law in C++?
are you retarded? Do you have Suleyman? ;)
you never declared any of your upper or lower variables
you need your returns to be return(0);
and you're missing a '}' after the last return.
Reply:Good answer! Would be best, if you didn't call him retarded, though.
Use a syntax checker that will show you on which line something is wrong. Report It
Reply:Do you have "lowery" and "uppery" defined?
love song
#include %26lt;iostream%26gt;
using std::cin;
int main()
{
// input range to scan values
cin %26gt;%26gt; lowerx;
cin %26gt;%26gt; upperx;
// loop over all combinations of x and y
for (int x = lowerx; x %26lt; upperx; x++)
{
for (int y = lowery; y %26lt; uppery; y++)
{
if (!(x%26lt;5)%26amp;%26amp;!(y%26gt;=7) != !((x%26lt;5)||(y%26gt;=7))) // test equivalence
{
printf("Expressions are not equivalent. x = %d, y = %d", x, y);
return;
}
}
}
printf("Expressions are equivalent over the specified range");
return;
De Morgans Law in C++?
are you retarded? Do you have Suleyman? ;)
you never declared any of your upper or lower variables
you need your returns to be return(0);
and you're missing a '}' after the last return.
Reply:Good answer! Would be best, if you didn't call him retarded, though.
Use a syntax checker that will show you on which line something is wrong. Report It
Reply:Do you have "lowery" and "uppery" defined?
love song
Need help with a C Program?
#include %26lt;stdio.h%26gt;
void main(void)
{
int a,i,j;
clrscr();
for(i=5; i%26gt;=1; i--)
{
for(j=1; j%26lt;=i; j++)
printf("%d",j);
printf("\n");
}
getche();
}
I need the Output as:
12345
2345
345
45
5
Thanks in advance...need it Urgently
Need help with a C Program?
ok here the code that i came up with also do you need that clrscr function if so sorry:
#include %26lt;stdio.h%26gt;
void main(void)
{
int a=1,i,j;
for(i=5; i%26gt;=1; i--)
{
for(j = a; j%26lt;=5; j++)
{
printf("%d",j);
}
printf("\n");
a++;
}
return;
}
the reason yours kept counting down is cause everytime you went back into the second for loop the was intialaited to one so i add a and had it counted up every time the second for loop was finished and just had the condition for the j loop be that it was less then or equal to five instead of i cause eveventally it would catch up at 3 so I hope this helps without the clrscr
EDIT: to albert this is C not C++ but that would work instead of using a you could just set it equal to i and it would do the same thing with less varibales and use less resources
Reply:#include %26lt;stdio.h%26gt;
void main(void)
{
clrscr();
int x=0, y=0;
for(x=1;x%26lt;=5;x++){
for(y=x;y%26lt;=5;y++){
printf("%d",y);
}
printf("\n");
}
getch();
}
Kindly try this.
Reply:Why do not you contact a freelancer from websites like http://getafreelnacer.com/ ?
Reply:#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
void main()
{
int a,i,j;
clrscr();
for(i=1; i%26lt;=5; i++)
{
for(j=i; j%26lt;=5; j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
this program is a litlle altered but it will work.Wat this program does is that it will print the innner loop value and the condition is that is %26lt;=5 so first run of loop it will run from 1 to 5 then scond time 'j' will be initialised to 2 and not 1 as i have said j=i so therefore it will print from 2 to 5 and so on until last time it will print only 5 this program should work in case i am wrong plz forgive me.thank you
void main(void)
{
int a,i,j;
clrscr();
for(i=5; i%26gt;=1; i--)
{
for(j=1; j%26lt;=i; j++)
printf("%d",j);
printf("\n");
}
getche();
}
I need the Output as:
12345
2345
345
45
5
Thanks in advance...need it Urgently
Need help with a C Program?
ok here the code that i came up with also do you need that clrscr function if so sorry:
#include %26lt;stdio.h%26gt;
void main(void)
{
int a=1,i,j;
for(i=5; i%26gt;=1; i--)
{
for(j = a; j%26lt;=5; j++)
{
printf("%d",j);
}
printf("\n");
a++;
}
return;
}
the reason yours kept counting down is cause everytime you went back into the second for loop the was intialaited to one so i add a and had it counted up every time the second for loop was finished and just had the condition for the j loop be that it was less then or equal to five instead of i cause eveventally it would catch up at 3 so I hope this helps without the clrscr
EDIT: to albert this is C not C++ but that would work instead of using a you could just set it equal to i and it would do the same thing with less varibales and use less resources
Reply:#include %26lt;stdio.h%26gt;
void main(void)
{
clrscr();
int x=0, y=0;
for(x=1;x%26lt;=5;x++){
for(y=x;y%26lt;=5;y++){
printf("%d",y);
}
printf("\n");
}
getch();
}
Kindly try this.
Reply:Why do not you contact a freelancer from websites like http://getafreelnacer.com/ ?
Reply:#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
void main()
{
int a,i,j;
clrscr();
for(i=1; i%26lt;=5; i++)
{
for(j=i; j%26lt;=5; j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
this program is a litlle altered but it will work.Wat this program does is that it will print the innner loop value and the condition is that is %26lt;=5 so first run of loop it will run from 1 to 5 then scond time 'j' will be initialised to 2 and not 1 as i have said j=i so therefore it will print from 2 to 5 and so on until last time it will print only 5 this program should work in case i am wrong plz forgive me.thank you
My answer to my c language question,pls check it for me..?
this is my answer to my question that i wrote yesterday...
#include %26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
double hypotenuse(double,double);
double hypotenuse(double a,double b)
{
return sqrt((a*a)+(b*b));
}
void main()
{
double side1,side2;
int i;
for(i=0;i%26lt;=3;i++)
{
printf("Enter side 1 and side 2 for triangle %d :",i+1);
scanf("%f%f",%26amp;side1,%26amp;side2);
printf("Hypotenuse for triangle %d is %f",i+1,hypotenuse(double,double));
}
return 0;
}
My answer to my c language question,pls check it for me..?
I personally would ask for the 2 sides separately. The scanf seems to be the only possible issue. I don't know how it separates the 2 floating point numbers.
#include %26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
double hypotenuse(double,double);
double hypotenuse(double a,double b)
{
return sqrt((a*a)+(b*b));
}
void main()
{
double side1,side2;
int i;
for(i=0;i%26lt;=3;i++)
{
printf("Enter side 1 and side 2 for triangle %d :",i+1);
scanf("%f%f",%26amp;side1,%26amp;side2);
printf("Hypotenuse for triangle %d is %f",i+1,hypotenuse(double,double));
}
return 0;
}
My answer to my c language question,pls check it for me..?
I personally would ask for the 2 sides separately. The scanf seems to be the only possible issue. I don't know how it separates the 2 floating point numbers.
How do I use C to program a delay?
Just for example. How would I get the programme to say:
printf("blah blah");
Then delay here for a set length of time
printf("blah blah blah");
And so on..
How do I use C to program a delay?
on a unix system you would call sleep(seconds);
Reply:Why don't you join one of the hundreds of C forums or user groups where answers to your question will continue for weeks. You will learn far more from these groups than by asking a single question here. That's how I learned to program.
Reply:Here's one way. The time function is found in (at least) DOS, Unix, Win16, Win32, ANSI C, ANSI C++ and OS/2.
Your compiler may offer a better function. For instance, on a DOS, Unix, Win32 or OS/2 system, you could use sleep(), but that's not ANSI C. What I'm offering here uses up a lot of CPU cycles, so it would be OK on an individual PC, but it would not be very acceptable on a multiuser system such as a server.
#define DELAY 4
#include %26lt;time.h%26gt;
#include %26lt;stdio.h%26gt;
int main(void)
{
time_t begin, end;
end = begin = time(NULL);
printf("blah blah");
while ((end - begin) %26lt; DELAY)
{
end = time(NULL);
}
printf("blah blah blah");
return 0;
}
Reply:There is a function in C that works for delaying or sleeping for a certain amount of time....most times, this time is specified in microseconds (i think so...its been long since i used C).
delay( )
The delay( ) function found in dos.h is processor dependent. And it won't work on all
systems. The reason is the delay function is implemented with clock speed.
Simply try writting "delay(400);" It might just work.
Dont forget to include "dos.h", thats the header file for delay function.
Reply:#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;dos.h%26gt;
main()
{
printf("blah blah");
delay(1500);
printf("blah blah blah");
getch();
}
printf("blah blah");
Then delay here for a set length of time
printf("blah blah blah");
And so on..
How do I use C to program a delay?
on a unix system you would call sleep(seconds);
Reply:Why don't you join one of the hundreds of C forums or user groups where answers to your question will continue for weeks. You will learn far more from these groups than by asking a single question here. That's how I learned to program.
Reply:Here's one way. The time function is found in (at least) DOS, Unix, Win16, Win32, ANSI C, ANSI C++ and OS/2.
Your compiler may offer a better function. For instance, on a DOS, Unix, Win32 or OS/2 system, you could use sleep(), but that's not ANSI C. What I'm offering here uses up a lot of CPU cycles, so it would be OK on an individual PC, but it would not be very acceptable on a multiuser system such as a server.
#define DELAY 4
#include %26lt;time.h%26gt;
#include %26lt;stdio.h%26gt;
int main(void)
{
time_t begin, end;
end = begin = time(NULL);
printf("blah blah");
while ((end - begin) %26lt; DELAY)
{
end = time(NULL);
}
printf("blah blah blah");
return 0;
}
Reply:There is a function in C that works for delaying or sleeping for a certain amount of time....most times, this time is specified in microseconds (i think so...its been long since i used C).
delay( )
The delay( ) function found in dos.h is processor dependent. And it won't work on all
systems. The reason is the delay function is implemented with clock speed.
Simply try writting "delay(400);" It might just work.
Dont forget to include "dos.h", thats the header file for delay function.
Reply:#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;dos.h%26gt;
main()
{
printf("blah blah");
delay(1500);
printf("blah blah blah");
getch();
}
Subscribe to:
Posts (Atom)