in Object Oriented Programming edited by
108 views
0 votes
0 votes
Trying out a code to get all the possible marks that can be obtained in a GATE paper.
Assumptions taken :

1) All questions are MCQs (all questions have a chance of negative marking)
2) 30 1-mark questions, 35 2-mark questions
3) Static array without any memory constraint to hold the values of marks
4) Unoptimized solution: the array can have duplicate values of marks

Here is the basic code that I have come up with

#include <stdio.h>

int main()

{   

    float a[1000] = {0};

    // 30 1-mark MCQ, 35 2-mark MCQ

    

    

    int x,y,k=0;

    float score;

    for(x=-30;x<=30;x++)

    {

        for(y=-35;y<=35;y++)

      {

            

        

        if(x<0)

        {

            if(y<0)

            score= 0.33*x + 0.66*y;

            else

            score= 0.33*x + 2*y;

        }

        

        else

        {

            if(y<0)

            score= 1*x + 0.66*y;

            else

            score= 1*x + 2*y;

        }

        a[k]=score;

        k++;

        

      }    

    }

    for(int i = 0; i<(sizeof(a)/sizeof(float)) ;i++)

    printf("%f", a[i]);

    

    return 0;

}

The console doesn't output anything.

Any suggestions on where might I be going wrong/ the error lies?
in Object Oriented Programming edited by
108 views

2 Comments

Your value of k is exceeding the array size.
1
1
Got it. Started working but still isn't giving correct output
0
0

Please log in or register to answer this question.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true