PLEASE HELP ME ! PLEASE

V

vubaboota

I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C
Q1:
Write a program using malloc function. In which you take input from
user and allocate memory equal to square of this number. Which
multiply numbers and draw a table in the following format?

Hint: User enters 3 then program allocates equal to 9 integer
memories.

Output:1

Enter a single digit number:
2
The multiplication table of 2 is:
1 2
----------------
1| 1 2
2| 2 4

Output:2

Enter a single digit number:
4
The multiplication table of 4 is:
1 2 3 4
--------------------------------
1| 1 2 3 4
2| 2 4 6 8
3| 3 6 9 12
4| 4 8 12 16


Q:2
Write a macros in which swap two number without using 3rd variable and
then call
Macro in main function.

Hint: a=4, b=2 after swapping a=2, b=4.


KINDLY HELP ME TO MADE THIS PRGRAM GUIDE ME OR GIVE ME CODE OF THE
ABOVE PROBLEM
 
J

Joachim Schmitz

vubaboota said:
I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C
Please don't shout at us. (hint: a sentence in all capitals is considered
shouteing in usenet)
Seems you had a serious problem in the classroom, paying attention to your
teacher.
Q1:
Write a program using malloc function. In which you take input from
user and allocate memory equal to square of this number. Which
multiply numbers and draw a table in the following format?

Hint: User enters 3 then program allocates equal to 9 integer
memories.

Output:1

Enter a single digit number:
2
The multiplication table of 2 is:
1 2
----------------
1| 1 2
2| 2 4

Output:2

Enter a single digit number:
4
The multiplication table of 4 is:
1 2 3 4
--------------------------------
1| 1 2 3 4
2| 2 4 6 8
3| 3 6 9 12
4| 4 8 12 16


Q:2
Write a macros in which swap two number without using 3rd variable and
then call
Macro in main function.

Hint: a=4, b=2 after swapping a=2, b=4.


KINDLY HELP ME TO MADE THIS PRGRAM GUIDE ME OR GIVE ME CODE OF THE
ABOVE PROBLEM
Try doing your homework yourself. Come back here if you have problems and
show what you've done so far.

Bye, Jojo
 
F

Flash Gordon

vubaboota wrote, On 05/06/07 07:44:
I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C
Q1:

KINDLY HELP ME TO MADE THIS PRGRAM GUIDE ME OR GIVE ME CODE OF THE
ABOVE PROBLEM

The best help anyone can give you is to tell you to attempt to do your
own homework. Well, that and DON'T SHOUT!
 
C

Chris Johnson

I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C
Q1:
Write a program using malloc function. In which you take input from
user and allocate memory equal to square of this number. Which
multiply numbers and draw a table in the following format?

Hint: User enters 3 then program allocates equal to 9 integer
memories.

Output:1

Enter a single digit number:
2
The multiplication table of 2 is:
1 2
----------------
1| 1 2
2| 2 4

Output:2

Enter a single digit number:
4
The multiplication table of 4 is:
1 2 3 4
--------------------------------
1| 1 2 3 4
2| 2 4 6 8
3| 3 6 9 12
4| 4 8 12 16

Q:2
Write a macros in which swap two number without using 3rd variable and
then call
Macro in main function.

Hint: a=4, b=2 after swapping a=2, b=4.

KINDLY HELP ME TO MADE THIS PRGRAM GUIDE ME OR GIVE ME CODE OF THE
ABOVE PROBLEM

These problems seem relatively well described. Is there something
you're having trouble understanding? At least start on these problems,
yourself. That way, when you run into trouble, you can ask specific
questions and get useful answers. I wouldn't count on anybody doing
your homework for you.
 
U

Umesh

//swapping

#include"stdio.h"
int main()
{
int a,b;
printf("Enter values of a & b : ");
scanf("%d%d",&a,&b);
a=a+b; //if a=4,b=2 now a=a+b=6
b=a-b; //now b=a-b=6-2=4
a=a-b;//now a=6-4=2
printf("After swapping\n a=%d \t b=%d",a,b);
return 0;
}

//table (allocate memory by yourself!)
#include"stdio.h"
void main()
{
int j=1,k=1,l=1;
int a;
printf("Enter a single digit number: ");
scanf("%d",&a);
printf("\nThe multiplication table of %d is:\n",a);
//formatting
for(l=1;l<=a;l++)
printf("\t%d",l);
printf("\n");
for(l=1;l<=8*a;l++)
printf("-");
printf("\n");
//result
while(j<=a){
printf("%d|\t",k); //formatting
for(int i=1;i<=a;i++)
printf("%d\t",i*j);
printf("\n");k++;
j++;}
}
 
M

mark_bluemel

I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C

First point - don't type in CAPITALS. It is taken as SHOUTING and is
impolite. Many people will choose to ignore your post, or killfile you
(ensure that they don't see anything your post again).

Second point - this newsgroup is not "comp.lang.c.do.my.homework". We
are not here to make up for your lack of attention in class, your
unwillingness to approach your teacher for assistance or your complete
incompetence. If you are learning, you have to make some effort
yourself - write some initial attempts at solving the problems set,
and then you can, politely, ask the group for assistance when you
encounter difficulties with what _you_ have written.
Q1:
Write a program using malloc function. In which you take input from
user and allocate memory equal to square of this number. Which
multiply numbers and draw a table in the following format?

Odd english in the question, but still it's fairly clear what is
required.

How would you get input from the user? (Hint: I'd recommend not using
scanf()).
How do you convert the input to a numeric?
How would you square the number?

Producing the output is trivial, surely. A loop to do the headings,
followed by a loop, with a nested loop for each row.

What have you tried? What problem did you encounter?
Hint: User enters 3 then program allocates equal to 9 integer
memories.

Output:1

Enter a single digit number:
2
The multiplication table of 2 is:
1 2
----------------
1| 1 2
2| 2 4

Output:2

Enter a single digit number:
4
The multiplication table of 4 is:
1 2 3 4
--------------------------------
1| 1 2 3 4
2| 2 4 6 8
3| 3 6 9 12
4| 4 8 12 16

Q:2
Write a macros in which swap two number without using 3rd variable and
then call
Macro in main function.

Hint: a=4, b=2 after swapping a=2, b=4.

This was recently discussed in the group - a Google search would find
the discussion. It may also be discussed in the FAQ (Frequently Asked
Questions) at c-faq.com - it's so completely pointless and irrelevant
a task to what I do, that I haven't looked. I seem to recall the trick
involves XOR and I also seem to recall that there are shortcomings to
it, but as I say, I haven't spent a lot of time or energy on looking
into it.
 
C

Chris Dollin

Umesh said:
a=a+b; //if a=4,b=2 now a=a+b=6
b=a-b; //now b=a-b=6-2=4
a=a-b;//now a=6-4=2

Pointless pointless ungeneralisable pointless trickery, with the nice
possibility for undefined behaviour pointlessly thrown in for "free".

Now you've seen it, (a) never use it [1], (b) work out three ways why
it's a bad idea, (c) never use it.

[1] Unless there are utterly overwhelming reasons why you must; if there
ever are, come back here & tell us about them.

--
Is it a bird? It is a plane? No, it's: http://hpl.hp.com/conferences/juc2007/
WARNING. Various parts of this product may be more than one billion years old.

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN
 
G

Guru Jois

//swapping

#include"stdio.h"
int main()
{
int a,b;
printf("Enter values of a & b : ");
scanf("%d%d",&a,&b);
a=a+b; //if a=4,b=2 now a=a+b=6
b=a-b; //now b=a-b=6-2=4
a=a-b;//now a=6-4=2
printf("After swapping\n a=%d \t b=%d",a,b);
return 0;

}
a^=b^=a; // could be still better than 3 statements.

But anyway Mr Umesh don't spoon feed askers. Don't think that we don't
know the answer, all are denying the answer to make these lazy asker
self-dependents.

Bye
Guru Jois
 
M

Martin Ambuhl

Umesh said:
//swapping

#include"stdio.h"
^^^^^^^^^
Unless you have your own private version of stdio.h, you should use the
standard header said:
int main()
{
int a,b;
printf("Enter values of a & b : ");
scanf("%d%d",&a,&b);
a=a+b; //if a=4,b=2 now a=a+b=6

// style comments in posted code is a bad idea. // style comments for
any pre-C99 compiler are just plain wrong.

This is very, very bad.
1) Suppose a+b > INT_MAX. What do you think your code will do?
2) The OP wrote "Write a macros in which swap two number without using
3rd variable". What makes you think all numbers are ints?
3) This is not a macro.

The worst thing, of course, is not your program but the inane question.
The correct answer is "don't do that; don't even try."
b=a-b; //now b=a-b=6-2=4
a=a-b;//now a=6-4=2
printf("After swapping\n a=%d \t b=%d",a,b);
return 0;
}

//table (allocate memory by yourself!)

That's fair. Leave something for him to do himself.
#include"stdio.h"
^^^^^^^^^
see above
void main()
^^^^
This is silly. main returns an int in a hosted environment. There has
never been a standard for C in which main was defined as returning void.
{
int j=1,k=1,l=1;
int a;
printf("Enter a single digit number: ");
scanf("%d",&a);

Quite apart from the highly vulnerable form of input, with no error
checking, the above needs a fflush(stdout); after the prompt. I/O on
stdin and stdout need not be synchronous.

Note that a is not checked for being a single-digit number.
printf("\nThe multiplication table of %d is:\n",a);
//formatting
for(l=1;l<=a;l++)
printf("\t%d",l);
^^
*Never* use '\t' in output designed to be read by humans. Display
devices can interpret '\t' is widely differing ways and you have no idea
when you are writing your program what '\t' will end up as on output.
printf("\n");
for(l=1;l<=8*a;l++)
^^
You pulled that '8' out of empty air. You have no reason to expect
that 8 is an appropriate choice.
printf("-");
printf("\n");
//result
while(j<=a){

Don't rely on the initialization at the top of the block here. The
for(;;) construct is a much better approach.
printf("%d|\t",k); //formatting
^^
'k' is a superfluous variable. There is no information associated
with k not already present in the variable 'j'.
for(int i=1;i<=a;i++)
^^^
This is illegal for pre-C99 compilers. For C99 compilers, it creates
a needless confusion by shadowing the already declared 'i' with block scope.
printf("%d\t",i*j);
printf("\n");k++;
j++;}
}

To the original poster: If you turn in "Umesh"'s code, you will get the
grade you deserve. You will not like it.
 
M

Martin Ambuhl

Guru said:
a^=b^=a; // could be still better than 3 statements.

No, it is horrid. The OP poster asked about swapping two number [sic].
The '^' operator requires operands of an integer type. And that's not
all that's wrong with it. This question has been beaten to death
before. If you really are committed to the silly XOR trick, check the
FAQ and the newsgroup archives to find out why you shouldn't be. You
might also find out why, even when the silly XOR trick works, writing it
as a single statement is a bad idea.
 
R

Richard

Martin Ambuhl said:
Guru said:
a^=b^=a; // could be still better than 3 statements.

No, it is horrid. The OP poster asked about swapping two number
[sic]. The '^' operator requires operands of an integer type. And

Don't be so ridiculous. By your rationale then the numbers to be swapped
could be different types and thus unswappable. At times it pays to maybe
consider the context the questions are asked in and give a cautious
reply along the lines of ...

"assuming we are talking about unsigned integers then one way might be ...."
that's not all that's wrong with it. This question has been beaten to
death before. If you really are committed to the silly XOR trick,
check the FAQ and the newsgroup archives to find out why you shouldn't
be. You might also find out why, even when the silly XOR trick works,
writing it as a single statement is a bad idea.

Students who come here asking these type of questions are rarely in the
position to slap their lecturers.
 
R

Richard

Joachim Schmitz said:
Please don't shout at us. (hint: a sentence in all capitals is considered
shouteing in usenet)
Seems you had a serious problem in the classroom, paying attention to your
teacher.

Is this a new record?

14 posts.

9 of them are discourteous warnings about posting style, homework and
things being off topic.
 
J

Joachim Schmitz

Richard said:
Is this a new record?

14 posts.

9 of them are discourteous warnings about posting style, homework and
things being off topic.
Where have I been discourteous?
My answer was the first (according to the timestapms I can see), so why are
you apparently atacking me for the # of posts?
 
C

Chris Hills

Is this a new record?
No

14 posts.
9 of them are discourteous warnings about posting style, homework and
things being off topic.

What has happened is we are getting far more posts of the "PLS DO MY
HOMEWORK URGENT" type.

These are clearly from people that use this NG as a start point without
reading any other posts here or doing an online search first.

Their lack of effort is therefore rewarded in kind.
 
C

Chris Hills

Martin Ambuhl said:
^^^^^^^^^
Unless you have your own private version of stdio.h, you should use the
standard header <stdio.h>.

The whole point of this code is that if the student uses it without
understanding it they will get spotted as a CHEAT
To the original poster: If you turn in "Umesh"'s code, you will get
the grade you deserve. You will not like it.

Correct..... If they want to cheat they have to take the consequences.
 
R

Richard

Chris Hills said:
What has happened is we are getting far more posts of the "PLS DO MY
HOMEWORK URGENT" type.

The why dont "we" agree that only ONE reply is enough. Why is there the
constant feeding frenzy. Leave it alone to see if someone else replies
or ignore it.
These are clearly from people that use this NG as a start point
without reading any other posts here or doing an online search
first.

Their lack of effort is therefore rewarded in kind.

--
 
R

Richard

Joachim Schmitz said:
Where have I been discourteous?
My answer was the first (according to the timestapms I can see), so why are
you apparently atacking me for the # of posts?

Where did I attack you?

And personally, I think (and I quote)

"Seems you had a serious problem in the classroom, paying attention to
your teacher."

Is pretty discourteous.
 
B

banansol

Is this a new record?

14 posts.

9 of them are discourteous warnings about posting style, homework and
things being off topic.


Oh please give it a break, Richard. While others on this NG
help out giving topical answers and telling people when they
are offtopic, you only seem to spewing out complaints about
answers all the time. Why don't you just do like others and
help people with C, that's what this group is for, like you say.
Much more helpful.

You have been told this before. And I'll just killfile you
if you continue, just wanted to say this before that.
 
R

Richard

Oh please give it a break, Richard. While others on this NG
help out giving topical answers and telling people when they
are offtopic, you only seem to spewing out complaints about
answers all the time. Why don't you just do like others and
help people with C, that's what this group is for, like you say.
Much more helpful.


I frequently do and have done so.

But the pollution level in this NG is second to none. There has
developed a policy of elitist competition between show offs and
wannabees. I find it faintly embarrassing as well as highly
distasteful. And it is getting worse.

There is a big difference between being a savager of nOObs and someone
who pleas for a bit of sanity.

Killfile me for all I care. I really don't mind.

I would also suggest you add posters whose net nanny to help ratio is
more than 1:1.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

HELP PLEASE 4
Code help please 4
I dont get this. Please help me!! 2
Help me 4
Please help 2
Total Purchase. Please Help 1
Help please 8
Can anyone please help me in this code 1

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top