From: Manish Katiyar <mkatiyar@gmail.com>
To: spiros85 <spirosfr_1985@hotmail.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: C program help
Date: Sat, 19 Sep 2009 21:21:54 +0530 [thread overview]
Message-ID: <ea11fea30909190851s3f8c5d80ge686092fc0572eae@mail.gmail.com> (raw)
In-Reply-To: <25522429.post@talk.nabble.com>
On Sat, Sep 19, 2009 at 8:43 PM, spiros85 <spirosfr_1985@hotmail.com> wrote:
>
> Hi guys of dear forum!I am a new programmer in C programming language and i
> have a question for you about the following C code:
> #include <stdio.h>
> #include <stdlib.h>
>
> int main()
> {
> int x;
> int answer;
> int right;
> int wrong;
> printf("This is a program of sum\n");
> right = 0; /*Initialization of right value*/
> wrong = 0; /*Initialization of wrong value*/
> for(x = 1; x <= 10; x++)[QUOTE][/QUOTE]
> {
> printf("What is %d + %d: ", x, x);
> scanf("%d", &answer);
> printf("The sum is %d\n", answer);
> printf("\a");
> if(answer == x + x)
> {
> printf("%d is RIGHT answer\n", answer);
> right++; /*Saves and increases the amount of right answers*/
> }
> else
> {
> printf("%d is WRONG answer\n", answer);
> b[10] = answer;
> wrong++; /*Saves and increases the amount of wrong answers*/
> printf("The correct answer is %d\n", x + x);
> }
> }
> printf("The right answers are %d and the wrong are %d\n", right, wrong);
> fflush(stdin);
> getchar();
> }
>
> First, I use DEV C++ compiler!This program asks from user to find the sum of
> 1+1,2+2 until for loop reaches 10.As you can observe with right++ and
> wrong++ i can define and print to the screen the amount of right or wrong
> numbers!
> My question is how could I define the number of correct and wrong numbers in
> collaboration with their amount?For example:
> The right answers are 8 and wrong are 2
> The right answers are 2 4 6 8 10 12 14 16
> The wrong answers are 22 44
#include<stdio.h>
#define N 10
int main() {
int answer;
int i;
int result[N][2];
int right = 0, wrong = 0;
for (i=1;i<=N;i++) {
printf("What is %i + %i ? :",i,i);
scanf("%d",&answer);
if (i+i == answer) {
result[i-1][0] = answer;
result[i-1][1] = 1;
right++;
} else {
result[i-1][0] = answer;
result[i-1][1] = 0;
wrong++;
}
}
printf ("The right answers are %d and wrong answers are %d\n",right, wrong);
printf("The right answers are : ");
for (i=0;i<N;i++) {
if (result[i][1]) {
printf("%d ", result[i][0]);
}
}
printf("\n");
printf("The wrong answers are : ");
for (i=0;i<N;i++) {
if (!result[i][1]) {
printf("%d ", result[i][0]);
}
}
printf("\n");
return 0;
}
> --
> View this message in context: http://www.nabble.com/C-program-help-tp25522429p25522429.html
> Sent from the linux-c-programming mailing list archive at Nabble.com.
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
--
Thanks -
Manish
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2009-09-19 15:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-19 15:13 C program help spiros85
2009-09-19 15:38 ` Tim Walberg
2009-09-19 15:51 ` Manish Katiyar [this message]
2009-10-09 12:10 ` shiva kumar
2009-12-29 4:50 ` vignesh1988i
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ea11fea30909190851s3f8c5d80ge686092fc0572eae@mail.gmail.com \
--to=mkatiyar@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
--cc=spirosfr_1985@hotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).