100% found this document useful (1 vote)
159 views6 pages

2.1 The Following Code Is Not Displaying The Correct Output, Which Is 1500. Identify The Error

The code in question 2.1 is not displaying the correct output of 1500 because it is using the %f format specifier to print the integer variable si. It should use %d. The code in question 2.2 is not displaying any output because there is a syntax error in the printf statement - it is missing a comma between the string and format specifier. The code in question 2.3 has an error calculating the area of a circle because it is using ** instead of ^ for exponentiation in the radius calculation.

Uploaded by

prashantonline
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
159 views6 pages

2.1 The Following Code Is Not Displaying The Correct Output, Which Is 1500. Identify The Error

The code in question 2.1 is not displaying the correct output of 1500 because it is using the %f format specifier to print the integer variable si. It should use %d. The code in question 2.2 is not displaying any output because there is a syntax error in the printf statement - it is missing a comma between the string and format specifier. The code in question 2.3 has an error calculating the area of a circle because it is using ** instead of ^ for exponentiation in the radius calculation.

Uploaded by

prashantonline
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

2.1 The following code is not displaying the correct output, which is 1500. Identify the error.

#include<stdio.h>

#include<conio.h>

main()

// this program calculates the simple interest

int p,t, si;

float r;

p = 5000;

t = 4;

r = 7.5;

si = p*t*r/100;

clrscr();

printf("%f", si);

getch();

2.2 The following code is not displaying the output on the screen. Identify the error.

#include<stdio.h>

#include<conio.h>

main ()

/*this program allows you to enter a number

and display that number on the screen*/

int number;

printf("Enter a number ");

scanf("%d", &number);

printf("you have entered the number", number);


}

2.3 Identify the error in the following code

#include<stdio.h>

#include<conio.h>

main()

{//this program calculate the area of the circle

float area;

int radius=4;

area = 3.14*radius**2;

printf("%f", area);

2.4 Identify the error in the following code

#include<stdio.h>

#include<conio.h>

main()

{ // this program display hello on the 'screen'

char name;

name = 'hello';

printf("%c", name);

2.5 Identify the error in the following code

#include<stdio.h>

#include<conio.h>
typedef int no of students;

typedef int maximum marks;

main()

no of students num;

maximum marks max;

printf("enter the number of students");

scanf("%d",&num);

printf("Enter the maximum marks");

scanf("%d",&max);

printf("%d %d", naum, max);

getch();

2.6 Identify the error in the following code

#include<stdio.h>

#include<conio.h>

main()

const char x = 'Z';

int a = 4;

clrscr();

a = 5;

2.7 Identify the errors in the following code


#include<stdio.h>

#include<conio.h>

main()

int a = 5, c = 2, d = 4, n = 6;

float ans;

ans = 10.2/a + (2*a+(3c +4)/a*d/(12/n));

clrscr();

printf("%f", ans);

getch();

2.8 Identify the error in the following program.

#include<stdio.h>

#include<conio.h>

main()

char x, y;

int z;

x = a;

y = b;

z = x + y;

printf("%d", z);

getch();

2.9 Identify the error in the following code


#include<stdio.h>

#include<conio.h>

main()

enum fruits { apple, oranges, mango};

enum color {orange, red , pink};

enum fruits f;

enum color c;

f = apple;

c = pink;

clrscr();

printf("The value of the apple is %d\n", f);

printf("The value of the pink is %d\n",c);

getch();

2.10 The following is not displaying thr correct output. Identify the errors.

#include<stdio.h>

#include<conioh>

main()

int num;

clrscr();

printf("Enter a number ");

scanf("%d", &num);(num = 1?printf("The number entered id 1" );

getch();
}

2.11 What is the difference between the following two statements?

char *str = " Computer";

char arr[] = "Computer";

2.12 What is the output of the following program?

enum p {a = 1, b, c , d, f = 60, y};

printf("%d", y);

2.13 What is the output of the following program?

#include<stdio.h>

void main()

int i = 2, j = 3, k = 0;

int p;

p = (i , k, j );

printf("%d\n", p );

You might also like