Basics of 'C' Programming

 Basics of C Programming

1.1 Fundamentals of algorithms: Notion of algorithm,

Notations used for assignment statements and basic

control structures.

1.2 Introduction to ‘C’: General structure of ‘ C'

program, Header file, ‘main ()’ function.

1.3 Fundamental constructs of ‘C’: Character set,

tokens, keywords, Identifiers, Constants - number

constants, character constants, string constants,

Variables. Data types in ‘C’: Declaring variables, data

type conversion.

1.4 Basic Input and Output functions: input and output

statements using printf(), scanf() functions.

1.5 Assignments and expressions: simple assignment

statements, arithmetic operators, shift operators,

bitwise operators, sizeof operator.

Important Questions For Exam :-

1. List any four keywords used in C Program.

Ans :- 
  1. if
  2. else
  3. for
  4. while
  5. do
  6. struct
  7. int
  8. float
  9. char
  10. double
---------------×------------------××--------------------×---------------

2. Give the use of printf() statement.

Ans. :-  The printf() is a library function it is used to send formatted output to the screen. This prints the string present inside the quotation inside the brackets (). We need to include stdio.h header file to using the #include<stdio.h> statement.

Example :- 

#include<stdio.h>
#include<conio.h>
void main()
{
        int a=100
        clrscr();
        printf("a=%d",a);
        getch();
}

---------------×------------------××--------------------×---------------

3. Write a C program to accept any integer number and display it’s Hexadecimal and octal 
format.

Ans. :-

#include <stdio.h>
#include <conio.h>
void main()
{
    int x;
    clrscr();
    printf("\nEnter value of x:");
    scanf("%d",&x);
    printf("\nHexadecimal value=%x",x);
    printf("\nOctal value=%o",x);
    getch();
}

---------------×------------------××--------------------×---------------

4. What is Algorithm ?
Ans. :-  Algorithm is a theoretical representation of Program. Program is represented through steps.

---------------×------------------××--------------------×---------------

5. What is Flowchart ?
Ans. :-    Flowchart is a Graphical Representation of Program. It represents program graphically using flowchart's symbols.

---------------×------------------××--------------------×---------------

6. Write algorithm and draw flow-chart to print even numbers from 1 to 100.
Ans:-

Algorithm :-
  1. Start
  2. Initialize the variable i to 1.
  3. If i<=100 then goto step 4 otherwise goto step 7.
  4. if i%2==0 then goto step 5 otherwise goto step 6.
  5. Print number i
  6. Increment value of i and goto step-3.
  7. Stop

Flowchart  :- 



---------------×------------------××--------------------×---------------

7. Write a C Program to Find Greatest Among Three Numbers.

Code :- 

#include <stdio.h>

#include<conio.h>

void main() 

{

    int a,b,c;

    clrscr();

    printf("Enter 1st Number = ");

    scanf("%d",&a);

    printf("Enter 2nd Number = ");

    scanf("%d",&b);

    printf("Enter 3rd Number = ");

    scanf("%d",&c);

    printf("\n");

    if(a>b)

    {

        if(a>c)

        {

            printf("%d is greater",a);

        }

        else

        {

            printf("%d is greater",c);

        }

    }

    else

    {

        if(b>c)

        {

            printf("%d is greater",b);

        }

        else

        {

            printf("%d is greater",c);

        }

    }

    getch();

}

---------------×------------------××--------------------×---------------

8. Explain the use of comments in C Programming.

Ans. :-   C comments are used to understand the program. Comments in C language are human readable. 
Why to use C comments 
  1. C comments make code or program understandable.
  2. C comments make program readable.
In C language there are two types of comments.
  1. Single line comments
  2. Multi line comments
1.  Single line comments
                  Single line comments starts with double forward slash. This comment includes only single line comment.

Syntax :- 

//This is single line comment

2.   Multi line comments
                  Multi line comments starts with (/*) forward slash star and ends with (*/) star forward slash. We can write multiple lines in this comment.

Syntax :- 

/* This is multi line comment */

---------------×------------------××--------------------×---------------

9. State any four data types used in C language.

---------------×------------------××--------------------×---------------

10. Identifiers
Ans. :- 
  1. Identifiers are case sensitive.
  2. Identifiers are of two type i.e. user defined and system defined.
  3. Identifiers is nothing but name given to these elements.
  4. Identifiers are used by programmers to name function, variable, or label.
---------------×------------------××--------------------×---------------


Post a Comment

0 Comments