• edited by
508 views
0 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?

Please log in or register to answer this question.

Position:
Show:

Related questions

1 1 vote
0 0 answers
1.9k
1.9k views
Aibi asked Oct 30, 2017
1,867 views
What is the output of below code considering the size of short int is 2, char is 1 and int is 4 bytes.#include<stdio.h>main(){short int i = 20;char c = 97;printf("%d, %d,...
6 6 votes
4 4 answers
2.1k
2.1k views
GO Classes asked May 2, 2022
2,053 views
What will be output printed by the following program?#include<stdio.h main() { int c=4; switch(c) { c=c-1; case 4: printf("IITB ")...
7 7 votes
2 2 answers
1.2k
1.2k views
GO Classes asked May 2, 2022
1,203 views
Trace the execution of the following if statements and select the output from this code fragmentint main() { int a = 3, b = 7 ; if ( (a + b) % 2 != 0 ) { printf("tetrahed...