Computer Science, asked by remopotter, 1 year ago

int i;
int marks[20];
for (i=0;i<20;i++)
{
printf("enter the number");
scanf("%d",&marks[i];
if(marks[i]<40)printf("not successful");
if((marks[i]>=40)&&(marks[i]<60))printf("passed in second division):
if(marks[i]>=60 printf("passed in first division");
}
how will the program executes explain each segment

Answers

Answered by omegads03
0

int i; - This statement declares a variable named i as int data type.

int marks[20]; - Declares an array of size 20 named as marks as int data type.

The next is the body of the for loop. The initial value of the for loop is i=0 and the condition is i<20. if this condition is true then it enters to the for loop, otherwise it increments. In this case the condition is true. So it will enter into the loop. After entering into loop a message will print as ‘enter the number’ then it takes the value from the user and store it in the i index of the marks array i.e. at marks[0]. Then it will check the if conditions. If the mark in index 0 is less than 40 then it will print ‘not successful’. If the mark in index 0 is not less than 40 then it will check in the next if condition. Then it will check whether the mark in index 0 is greater than 40 and also it is less than 60 or not. If this condition is true then it will print ‘passed in second division’. If this condition is also not true then it will check to the next if condition. It will check whether mark in index 0 is greater than 60 or not. If this condition is true then it will print ‘passed in first division’. Then it will go back to the increment section. After incrementing i will be equal to 1. After that it will check with the index value 1. This will continue till the value of i  becomes less than 20.

 

Answered by mindfulmaisel
0

"First of all, I'll organize the code in proper formatting and then answer the question in reference to that code. So, the code given is as follows:

int i;  

int marks[20];

for (i=0;i<20;i++)  

{  

printf(enter the number);  

scanf(%d,&marks[i];

if(marks[i]<40)

printf(not successful);  

if((marks[i]>=40)&&(marks[i]<60))

printf(passed in second division);

if(marks[i]>=60)

printf(passed in first division);  

}

The above code inputs the marks of 20 subjects/students into an array of 20 elements and if the marks are less than 40, it print is not successful, otherwise if the marks of the student are more than 40 and less than 60, then it prints passed in second division else if marks are greater than 60, it prints passed in second division."

Similar questions