Computer Science, asked by prathm2281, 11 months ago

A maths teacher asks her students to give 3 examples for positive odd numbers. When the student specifies a correct answer, his/her score is incremented by 1. When the student specifies a positive even number, his/her score is decremented by 0.5. When the student specifies a negative number, he/she will not be given any more chances to correct his or her mistake and his/her score will be decremented by 1. So a student's turn comes to an end when he/she has correctly specified 3 positive odd numbers or when the student has specified a negative number. Some students didn't know the difference between odd numbers and even numbers and they made many mistakes and so it was difficult for the teacher to maintain the scores. The teacher asks for your help. Can you please help her by writing a program to calculate the score?

Answers

Answered by rekhaprajapati1984
3

Answer:

Sample Input 1: 1 3 5 Sample Output 1: 3.0

Sample Input 2: 1 2 5 6 7 Sample Output 2: 2.0

Sample Input 3: 2 -4 Sample Output 3: -1.5

Sample Input 4: 3 3 3 Sample Output 4: 3.0

Problem:

here i am not getting how to input multiple variables through single scanf

here is my code

#include<stdio.h>

int main()

{

int a,i;

float b=0;

for(i=1;i<=3;i++)

{

scanf("%d",&a);

do

{

if(a%2==0)

{

b=b-0.5;

}

if(a<0)

{

b--;

}

else if(a%2!=0)

{

b++;

}

printf("%.1f",b);

}

while(a%2!=0);

break;

}

return 0;

}

Answered by bipinvjohn
31

Answer:

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

int num;

float marks=0.0 ;

for(int i=0;i<3;)

{

cin>>num;

if(num<0)

{

marks=marks-1;

break;

}

else if(num%2==0)

{

marks=marks-0.5;

}

else{

marks=marks+1;

i++;

}

}

cout<<marks<<endl;

}

Similar questions