(XI) Ans to Ch-5 Assignment

A. No. -2 A. No. -3 A. No. -4 A. No. -5
A. No. -6 A. No. -7 A. No. -8 A. No. -9
A. No. -10 A. No. -11 A. No. -12 A. No. -13
A. No. -14 A. No. -15 A. No. -16 A. No. -17

Ch5 Assignment -1

  1. Draw classification chart of programming language.
  2. Check Book page : 238
  3. Compare program and programming language.
    • Program is the product of programming language.
    • Program can be created in short time period where as it takes long time period to create programming language.
    • Program can solve a particular problem where as using programming language we can make to solve many problems.
    • Program will be different as per user but the programming language will be same for all.
    • Example of program is to calculate area of rectangle where as example of programming language is C, C++, PHP, Java etc.
  4. List any five third generation language.
  5. List any five fourth generation language.
  6. List any three research area of fifth generation languages.

Ch5 Assignment -2

  1. List any three language translators.
  2. List any three interpreted programming languages.
  3. Ans: BASIC, LISP , Perl
  4. List any three compiler based programming languages.
  5. Ans: C, C++, Visual Basic
  6. Compare between compiler and interpreter.
  7. Draw figures of assembler, interpreter and compiler.
  8. Compare syntax and semantic of a programming language.
  9. Give an example of run time error.
Goto Top

Ch5 Assignment -3

  1. What are the three stages of program development?
  2. List any three program design tools.
  3. Write an algorithm to calculate area of square.
  4. Write an algorithm to calculate area of circle.
  5. Write an algorithm and a flowchart to calculate simple interest.
Goto Top

Ch5 Assignment -4

  1. What are the three major components of selection structure?
  2. Ans: Condition, True statement, False Statement
  3. List four types of selection structures.
  4. Ans: simple if , if-else, if-else ladder, nested if else
  5. Write an algorithm and a flowchart to check the number is positive or negative.
  6. Algorithm to check the number is positive or negative

    Step 1: Start
    Step 2: Input N
    Step 3: if(N>0)
    Output "Positive"
    else
    Output "Negative"
    Step 4: Stop
  7. Write an algorithm and a flowchart to check the number is odd or even.
  8. Algorithm to check the number is odd or even

    Step 1: Start
    Step 2: Input N
    Step 3: R= N%2
    Step 4: if(R==0)
    Output N is even.
    else
    Output N is odd.
    Step 5: Stop
  9. Write an algorithm and a flowchart to check the number is divisibly by 5.
  10. Algorithm to check the number is divisibly by 5

    Step 1: Start
    Step 2: Input N
    Step 3: R= N%5
    Step 4: if(R==0)
    Output N is divisibly by 5.
    Step 5: Stop
Goto Top
Ch5 Assignment -5
  1. What are the three components of a loop?
  2. What happens when the condition is always true in the loop?
  3. Write an algorithm and a flowchart to print 100,99,98,...1.
  4. Ans:

    Algorithm to print 100,99,98,...,1

    Step 1: Start
    Step 2: i=100
    Step 3: while(i>=1)
    {
    Output i
    i=i-1
    }
    Step 4: Stop
  5. Write an algorithm and a flowchart to print 1   3   5   .....N
  6. Ans:

    Algorithm to print 1   3   5   .....N

    Step 1: Start
    Step 2: i=1
    Step 3: Input N
    Step 4: while(i<=N)
    {
    Output i
    i=i+2
    }
    Step 5: Stop
  7. Write an algorithm and a flowchart to display multiplication table of 5.
  8. Ans:

    Algorithm to display multiplication table of 5

    Step 1: Start
    Step 2: i=1
    Step 3: while(i<=10)
    {
    Output 5*i
    i=i+1
    }
    Step 4: Stop
  9. Write the full form of BCD, ASCII, EBCDIC and Unicode.
Goto Top

Ch5 Assignment -6

  1. Who developed C language and when?
  2. Ans: Dennis Ritchie in 1972 AD
  3. List out any four major features of C langauge.
  4. List out the major four compenents of C program.
  5. Ans:
    (i) Preprocessors and Header files
    (ii)Comment
    (iii) Declaration Part
    (iv) Executable Part
  6. Draw a figure of compilation process in C programming.
  7. Compare source file, object file and executable file
  8. Ans: Source File: The file which contains original code of high level language is called source file. e.g. abc.c . This is the code collection written by the programmer.
    Source file is translated into machine understandable form called object file. e.g. abc.obj . Object file is created by the compiler.
    The linker produces an executable program located in a disk file with dot exe extension and the same name as the object file(for example, abc.obj is linked to create abc.exe).
Goto Top

Ch5 Assignment -7

  1. List any four header files and two pre-processor directives.
  2. Ans:
    (i) #include<stdio.h>
    (ii) #include<math.h>
    (iii) #include<string.h>
    (iv) #include<conio.h>
    Two pre-processor directives are: #include and #define.
  3. What is character set?
  4. Write the types of comments.
  5. Write six types of tokesn used in c langugage.
  6. Compare indentifiers and keywords.
Goto Top

Ch5 Assignment -8

  1. List any four data types and any four secondary data types.
  2. How much memory require to hold character, integer, float and double data types?
  3. Compare variable and constant.
  4. List any five types of constants.
  5. List any five escape sequence constants.
  6. List any five type specifier characters.
Goto Top

Ch5 Assignment -9

  1. Compare simple statement and compound statement.
  2. Ans:

    Simple statement:

    A simple statement consists of an expression followed by a semicolon. The execution of a simple statement causes the expression to be evaluated.
    Example:
    b=5;
    c=d+e;
    printf("Enter a number");

    Compound statement:

    A compound statement consists of several individual Statements enclosed in a pair of braces { } . It provides capability for embedding Statements within other statements.
    Example:
    {
    r=5;
    area=3.14*r*r;
    }
    It shows a compound statement to calculate the area of the circle.
  3. List out any five types of operators of c language.
  4. List any five arithmetic operators and any five relation operators.
  5. List any three logical operators.
Goto Top

Ch5 Assignment -10

  1. Compare operator and expressions.
  2. What is operand?
  3. Compare implicit type casting and explicit type casting.
  4. List any five library functions of c language.
Goto Top

Ch5 Assignment -11

  1. List out any four input functions and output functions.
  2. Write syntax and example of functions: scanf() and printf().
  3. Write syntax and example of functions: getchar() and putchar().
  4. Write syntax and example of functions: gets() and puts().
Goto Top

Ch5 Assignment -12

    if statement

  1. Write a C program to check whether the given number is positive.
  2. #include<stdio.h>
    main()
    {
    int num;
    printf( " Enter any number : ");
    scanf("%d",&num);
    if(num>0)
    printf( " %d is positive. ", num);
    }
  3. Write a C program to check whether the given number is odd.
  4. #include<stdio.h>
    main()
    {
    int num;
    printf( " Enter any number : ");
    scanf("%d",&num);
    if(num%2==1)
    printf( " %d is odd number. ", num);
    }
  5. Write a C program to check whether the given number is divisible by 5.
  6. #include<stdio.h>
    main()
    {
    int num;
    printf( " Enter any number : ");
    scanf("%d",&num);
    if(num%5==0)
    printf( " %d is divisible by 5. ", num);
    }

    if else statement

  7. Write a program to check whether the given number is odd or even.
  8. #include<stdio.h>
    main()
    {
    int num;
    printf( " Enter any number : ");
    scanf("%d",&num);
    if(num%2==1)
    printf( " %d is odd number. ", num);
    else
    printf( " %d is even number. ", num);
    }
  9. Write a program to check whether the given number is positive or negative.
  10. #include<stdio.h>
    main()
    {
    int num;
    printf( " Enter any number : ");
    scanf("%d",&num);
    if(num>0)
    printf( " %d is positive. ", num);
    else
    printf( " %d is negative. ", num);
    }

    if else if statement

  11. Write a program to check whether the given number is divisible by 5 and not divisible by 10.
  12. #include<stdio.h>
    main()
    {
    int num,r1,r2;
    printf( " Enter any number : ");
    scanf("%d",&num);
    r1=num%5;
    r2=num%10;
    if(r1==0&&r2!=0)
    printf( " %d is divisible by 5 but not by 10.\n ", num);
    else if(r1!=0&&r2!=0)
    printf( " %d is not divisible by 5 and 10.\n ",num);
    else
    printf( " %d divisible by both 5 by 10.\n ", num);
    }
  13. Write a program to find the largest number among four numbers given by the user.
  14. #include<stdio.h>
    main()
    {
    int a,b,c,d;
    printf( " Enter four numbers : ");
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a>b&&a>c&&a>d)
    printf("Largest number is %d ",a);
    else if (b>a && b>c && b>d)
    printf("Largest number is %d ",b);
    else if(c>a && c>b && c>d)
    printf("Largest number is %d ",c);
    else if(d>a && d>b && d>c)
    printf("Largest number is %d ",d);
    else
    printf("All numbers are same.");
    }
  15. Write a program to find the smallest number among five numbers given by the user.
  16. #include<stdio.h>
    main()
    {
    int a,b,c,d,e,small;
    printf( " Enter five numbers : ");
    scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
    if(a<b && a<c && a<d && a<e)
    small=a;
    else if (b<a &#38;& b<c && b<d && b<e)
    small=b;
    else if (c<a && c<b && c<d && c<e)
    small=c;
    else if (d<a && d<b && d<c && d<e)
    small=d;
    else
    small=e;
    printf("Smallest number is %d ",small);
    }
  17. Write a program to check the given number is positive, negative or zero.
  18. #include<stdio.h>
    main()
    {
    int num;
    printf(" Enter any number : ");
    scanf("%d",&num);
    if(num>0)
    printf(" %d is positive number. ",num);
    else if(num<0)
    printf(" %d is negative number. ",num);
    else
    printf(" You entered zero. ");
    }

    nested if else statement

  19. Write a program to find the largest number among two positive numbers.
  20. #include<stdio.h>
    main()
    {
    int a,b;
    printf(" Enter two numbers : ");
    scanf("%d%d",&a,&b);
    if(a>0 && b>0)
    {
    if(a>b)
    printf("%d is greater.",a);
    else
    printf("%d is greater.",b);
    }
    else
    printf(" Sorry ! You entered negative numbers. ");
    }
  21. Write a program to find the largest number among three positive numbers using nested if else statement.
  22. Write a program to find the given number is divisible by 5 and not by 10 using nested if else statement.
  23. switch statement

  24. Write a program to display the name of the day in a week, depending on the number entered through the keyboard using the switch statement.
  25. #include<stdio.h>
    main()
    {
    int choice;
    printf("Enter your choice betwen 1-7 : ");
    scanf("%d",&choice);
    switch(choice)
    {
    case 1:
    printf("Sunday");
    break;
    case 2:
    printf("Monday");
    break;
    case 3:
    printf("Tuesday");
    break;
    case 4:
    printf("Wednesday");
    break;
    case 5:
    printf("Thursday");
    break;
    case 6:
    printf("Friday");
    break;
    case 7:
    printf("Saturday");
    break;
    default:
    printf("Wrong Choice");
    }
    }
Goto Top

Ch5 Assignment -13
  1. Using while loop, display your name 10 times on screen.
  2. #include<stdio.h> main() { int i=1; while(i<=10) { printf(" (%d) Kripa Thapa\n", i); i++; } }
  3. Using while loop, display the series:
    10 9 8 ... to 1.
  4. #include<stdio.h> main() { int i=1; while(i>=1) { printf(" %d\t ", i); i--; } }
  5. Using while loop, calculate and display sum of odd natural numbers up to n.
  6. #include<stdio.h> main() { int i=1,n,sum=0; printf("Enter the value of n: "); scanf("%d",&n); while(i<=n) { sum=sum+i; i=i+2; } printf("Sum of odd natural numbers upto %d is %d ",n,sum); }
    Goto Top

Ch5 Assignment -14

  1. Using do while loop, calculate and display the series: 1   8   27    to 10th terms.
  2. Using do while loop, display the series: 15   9   ...    up to 20th term.
  3. Using do while loop, display multiplication table of any number given by the user.
Goto Top

Ch5 Assignment -15
  1. Write a program to display multiplication table of given number.
  2. Write a program to display the multiplication table with NxN terms.
  3. Write a program to display the odd series 1 3 5 .... N using continue statement.
  4. Write a program to show an infinite loop.
  5. Write a program to display the following output.
    333
    22
    1
Goto Top

Ch5 Assignment -16
  1. Define array and array index.
  2. List any two advantages and disadvantages of array.
  3. How is one dimensional array of integers initialized?
  4. How is two dimensional array of integers initialized?
  5. Write a program to find the smallest among the given set of numbers.
  6. Write a program to transpose of given matrix with size 2x2.
  7. Write a program to subtract two 2x2 matrices.
Goto Top

Ch5 Assignment -17
  1. Differentiate an array and a string.
  2. What is null character in a string?
  3. Compare between scanf() and gets() while entering a string.
  4. Write syntax and an example to define a table of strings.
  5. List any two string handling functions with respective syntax.
Goto Top
End of Ch-5 Assignment