Thursday, 29 June 2017
Friday, 12 May 2017
Thursday, 27 April 2017
Tuesday, 18 April 2017
Friday, 24 March 2017
XI STD DEBUG / OUTPUT
Debug the following program for the required output
# include<stdio.h>
$include<conio.h>
MAIN()
[
Int n
CLrSCR();
PRINTF(“In Enter the number:\n”;
SCAMF(“%d”,&n)
if(n%2= =0);
printf(“In the given number is even”);
else
printf(The given number is not even”);
getch();
}
WAY TO WRITE
1.
Write the
given program & set line numbers
2.
Tabulate with
headings line no, Error, Correction
3.
Write the
error prone line number and nature of error and correct form of statement
Answer To Be In Paper
|
# include<stdio.h>
$include<conio.h>
MAIN()
[
Int n
CLrSCR();
PRINTF(“In Enter the number:\n”;
SCAMF(“%d”,&n)
if(n%2= =0);
printf(“In the given number is even”);
else
printf(The given number is not even”);
getch();
}
Line No
|
Error
|
Correction
|
2
|
Preprocessor directive should start with #
|
#include<conio.h>
|
3
|
Function should return with value
Name should be as main()
|
void main()
|
4
|
[ should be replaced with {
|
{
|
5
|
All key words are to be written in small letters
Every completed line ends with ;
|
int n;
|
6
|
All key words are to be written in small letters
|
clrscr();
|
7
|
Closing bracket is missing
PRINTF – unknown function
|
printf(“\nEnter the number:\n”);
|
8
|
SCAMF – unknown function
Semicolon missing
|
scanf(“%d”);
|
9
|
If statement should not end with semicolon
|
If(n%2==0)
|
10
|
printf(“In
“In – should be replaced by \n
|
printf(“\n the Given
number is even”);
|
12
|
Opening quotation( “) is missing
|
printf(“The given number is not
even”);
|
**** ************ ************ *************** ******************* *****************
Question Write the output of the following program
Example
#include <stdio.h>
main()
int term;
int i;
i=1;
term=1;
while(term<=10)
{
printf(“%d \t”,i);
i=i+term;
term=term+1;
}
}
Way To Write
Rewrite the program in paper
1.
Analyze step by
step
2.
Go in the flow of
program
3.
Write whatever
the printf command follows as per the rule.
#include <stdio.h>
main()
{
int term;
int i;
i=1;
term=1;
while(term<=10)
{
printf(“%d \t”,i);
i=i+term;
term=term+1;
}
}
Output
1 2
4 7 11 16 22
29 37 46
|
Explanation of the program:
1.
Variable term, i
are declared and initialized with 1.
2.
Now in memory
i=term = 1
3.
So term<=10 is
true. While this true status the body of the loop followed within { } are repeated
o
i value 1 is printed with tab space
o
i value in memory
changed to 1+1=2
o
term value in
memory changed to 1+1=2
4.
term<=10 is true. While this true
status the body of the loop followed within {
} are repeated
o
i value 2 is printed with tab space
o
i value in memory
changed to 2+2=4
o
term value in
memory changed to 2+1=3
5.
term<=10 is true.
While this true status the body of the loop followed within { } are repeated
o
i value 4 is printed with tab space
o
i value in memory
changed to 4+3=7
o
term value in
memory changed to 3+1=4
.
.
In the same way analyze till
term<=10 becomes false.
Sunday, 26 February 2017
Subscribe to:
Posts (Atom)