Patrick wants to add credit points to his credit card. So he decided to play the card game – VIII which also helps in adding credit points. In this game, he has to pick the cards which are shuffled on the table until he picks the card with the number 999. Once he picks the card with number 999, Patrick must handover all the cards picked to Disneyland card game manager. The sum of all prime numbers in the cards picked by Patrick is credited as points to Patrick.
The players can pick any number of cards until the card with number 999 is encountered. So it is difficult for the Disneyland managers to sum up all prime card numbers. They approach you and ask for your help.
Can you please help them with the program to sum up all prime numbers in the cards picked (exclude 999 when calculating the sum) using while loop?

Input Format:
Input consists of a list of integers.

Output Format:
The output consists of a single line. Refer sample output for details.

[All text in bold corresponds to the input and the rest corresponds to output]

Sample Input and Output 1:
Enter the cards picked up by Patrick:
3
4
5
8
999
The credit points is 8

Sample Input and output 2:
Enter the cards picked up by Patrick:
9
11
1
999
The credit points is 11



Program Code:
#include<stdio.h>
int main(){
    int numbr,sum=0, remark, k;
    printf("Enter the cards picked up by Patrick:\n");
    scanf("%d",&numbr);
    
    while(numbr!=999)
   {
    remark=0;
    if(numbr!=1)
    {
    for(k=2; k<=numbr/2; k++)
   {
        if((numbr % k) == 0){
        remark++;
        break;
        }
    }
   if(remark==0)
   sum += numbr;}
   scanf("%d",&numbr);
   }
   printf("The credit points is %d ",sum);
   return 0;

}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

1 comments:

  1. An impressive share, I just given this onto a colleague who was doing a little bit evaluation on this. And he the truth is purchased me breakfast because I discovered it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to debate this, I really feel strongly about it and love reading more on this topic. If doable, as you become experience, would you mind updating your blog with extra particulars? It is extremely useful for me. Large thumb up for this blog submit! this website

    ReplyDelete