-->

NEB41:Explain datatypes used in “C”.

Q41)Explain datatypes used in “C”.

ans:-
 Data type:- 
  When we write program we use different variable. Before we use them in our program we declare them with their data format to be used in memory. This format is called 'data type'.
                              Following are the types.There are two types of data types.
                         a) Basic data type (Primary data type)
                         b) Derived data type(Secondary data type) mostly called "Qualifier"
                                          
  Let's have look in detail about primary data types.
                                a) Basic data type:- Under this category we have four types. They are int,float,char and double.Let's know about them.
                                                a.1) int:- 
                                                                It's a basic data type; we can use only integer type of value by declaring variable with this. e.g
                                                                                                int sum; 
                                                                           This declaration declares sum as integer type of variable. We can  use or input only integer type of value and under some range. We can not use other values like fractional or exponential. And if we used then, the computer truncates the fractional part. eg. int sum=3.4; 
                                                                                        Here, we used int data type but assigned fractional value (3.4); So computer stores only 3 instead of 3.4. It occupies 2 bytes in memory and working range is -32768 to +32767.
                                                a.2) float:-
                                                                    Suppose, we want to use fractional numbers; then we use float data type. This type supports numbers with decimal digits(after dot) for a variable. Unlike integer (int ), it does not truncate the fractional part and whole part is stored in memory. 
                                                                        float pi=4.67;
                                                                        float a=6;
                                                                         We have taken simple examples. In first. the computer stores 4.67 in memory. Where as in second we can see that number is integer but it has been declared as float, in this case computer automatically converts the integer into float by putting dot and zeros. i.e computer takes 6.00. In memory computer occupies 4 bytes for this and can store up to or in range 3.4e-38 to 3.4e+38;good range it has to work with.
                                                a.3) Char:-
                                                                         Char stands for a single character or sequence of many characters. We use this data type if we want to use one character or  a set (called string) to be inputted. To be clear, let's have an example,
                                                                                    syntax goes like,
                                                                                   data type variable/s;
                                                                                   char a,b;
                                                                    here, a and b are character type of variables and can store one character. If we want to store one character as a constant then we can assign like,
                                                                         char a='n';
                                                                          here, a is character type of variable and is storing 'n';
                                                                                                                                                                         But if we want to store more than one character or input then we can use,
                                                                      char a[10];
                                                                                                        here, we can enter a string having maximum ten characters;we can also enter just one character. This concept is called arrayed characters. In the case of constant,we use
                                                                    char a[10]="text"; 
                                                                    String "text" is stored in variable 'a' and it can store maximum 10 characters.
                                                        
                                                    a.4) Double:-  
                                                                             This data type is used  for exponential values and for more accuracy of digits.It's working range is more than others. so if we want to use long numbers of any type and high accuracy then...? for example,
                                                                                                            data type variable;
                                                                                                             double ab;
                                                                                                  'ab' is a variable of double type. It can store exponential values (3x104). It ca n be written as 3e+4 or 3E+4. If power is in negative form then it can be in 3e-4 or 3E-4. It has one advantage over others that it can be used in place of others easily.



neb40:Explain about operator and its types.

ans:
operator:- It is a symbol or a character used in programming. It is used to carry out some operation.
for example: +,-,= etc
It is of following types.
1)Arithmetic operator: It is used to do arithmetic calculations/operation.
 It has following types.

 +         -----------> used for addition.example is a+b. It means we are performing addition with the help of operand a and b
-           ------------>It is used for subtraction.Example is a-b.  It means we are performing subtraction with the help of operand a and b
* -------------------->used for multiplication.example is a*b. It means we are performing multiplication with the help of operand a and b
/---------------->used for division.example is a/b. It means we are performing division with the help of operand a and b
%---------------->used for remainder division.example is a%b. It means we are performing division with the help of operand a and b.It gives us remainder after division.

2)relational operator: 
This operator is used to perform comparisons between variables.It supports us to take decision logically. example,x>y ,x>=y etc
Relational operator has following types.


>------> It is used to show greater than. like x>y
>=----->It is used to show greater than or equals to.like x>=y
<-------->It is used to show a variable is smaller than another.like x<y
<=-------> It is used to show smaller than or equals to with another variable.Like x<=y
!=----------> I simply says , two variables are not equal in value.like x!=y
==---------->It says two variables have same value.It is used to test values of two variables.

3)Logical operator:-
                                   This operator is quite helpful when we want to combine multiple  conditions and take decision.It returns values in the form of 0 o 1.It works logically.
Its types are:

3.a)and (&&)-----------> It is called 'and'operator.It is used to combine multiple conditions.It gives us true output if all of them are true otherwise we get false output.
 example:if(a>b && a>c)
                      {
                            display a     
                        }
 we can see here that to be greatest,value of 'a' must be greater than b and c. So we use here '&&'
   
  3.b)or(||):- It is called 'or'operator.It is used to combine multiple conditions.It gives us true output if anyone of them is true or all are true otherwise we get false output.
 example:if(a==90 || b==90 || c==90)
                      {
                            display right angle triangle  
                        }
 we can see here that to be right angled triangle,either 'a'or 'b'or 'c' a must be 90 . So we use here '||'.

3.c) !(not )operator:-
                                It is used to reverse the result.
example
int a=5;
if(!(a==5))
{
printf("it is\n");
}
else
{
printf("it is not\n");
}
here ,the value is 5 but we get output "it is not".It is called reversing the output.

4) Assignment operator:
                                an operator ,symbolized by '=' character,is called assignment operator.It assigns value to variable.
example:
int a=6;
It means, we are assignming value 6 to variable a.

5)Unary operator:- this operator  works on one operand only.It has two types.
                               I) increment operator:- It increases the value of given variable by one.For example: ++y or y++
                                             It can be classified into pre-increment and post increment.
                                                 pre-increment:- It is written as ++x.It means first increase the value and then use that.
                                                 post-increment: It is written as x++.It means, first use that and then increase its value by one.

                               II)decrement operator:- It decreases the value of given variable by one.For example: --y or y--
                                             It can be classified into pre-decrement and post decrement.
                                                 pre-decrement:- It is written as --x.It means first decrease the value and then use that.
                                                 post-decrement: It is written as x--.It means, first use that and then decrease its value by one.


Besides these all, we have some other operators .like  bitwise,

neb42:WAP to show use of command “remove” and “rename” in data file handling with the help of example.

ans:
remove:this function is used to delete data file from the system.
syntax is:
remove("filename");

we have following example as a program.

//WAP to show use of command “remove” in data file handling with the help of example.
 #include<stdio.h>
#include<conio.h>
void main()
{
char choice;
printf("enter ur choice\n");
choice=getchar();
if(chice=='y')
        {
              remove("data.txt");
            printf("data file deleted sccessfully\n");
         }
else
{
printf("sorry, data filenot found\n");
}
getch();
}

rename: it is used to rename the file.
syntax is
rename("old name","new name");
 example is given below.
//WAP to show use of command “rename” in data file handling with the help of example.
 #include<stdio.h>
#include<conio.h>
void main()
{
char choice;
printf("enter ur choice\n");
choice=getchar();
if(chice=='y')
        {
              rename("data.txt","data1.txt");
            printf("data file renaming done successfully\n");
         }
else
{
printf("sorry, data file not found\n");
}
getch();
}


neb38:WAP to count total number of students having age in range 20 and 40 out of ‘n’ number of students.

//WAP to count total number of students having age in range 20 and 40 out of ‘n’ number of students
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,count=0;
in age[1000];
printf("enter total students' number-below 1000\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter age\n");
scanf("%d",&age[i]);
   if(age[i]>=20 && age[i]<=40)
              {
                count++;
              }
 }
printf("total students=%d\n",count);
getch();
}


neb39:Differentiate between break and continue with example

Differentiate between break and continue with example
ans:
differences are :

break
continue
1
It terminates the execution.
It takes the iteration to next level(skipping).
2
It can be used in loop and switch.
It can be used in switch
3
It uses keyword ‘break’.
It uses keyword ‘continue’.
4
Its syntax is
break;
Its syntax is
continue;
5
Example is
For(i=1;i<=4;i++)
{
  If(i<=2)
    Printf(“%d\n”,i);
     Break;
}
}
Example is
For(i=1;i<=4;i++)
{
  If(i<=2)
    Printf(“%d\n”,i);
     continue;
}
}

output is:1 
output is:1,2

neb37:Differentiate between while and do.. while loop.

Differentiate between while and do.. while loop.
ans:
Following are differences between while and do...while loop




while
Do..while
1
It is called pre-testing loop.
it is called post-testing loop
2
It uses keyword ‘while’.
it uses keyword ‘do.. while’
3
Its syntax is
Initialization;
While(condition)
{
Statement;
Increment/decrement;
}
 Its syntax is
Initialization;
do
{
Statement;
Increment/decrement;
              }while(condition);
4
nothing will happen if the condition is false.
 even after false(condition), it will run at least once.
5
Its flowchart is



Its flowchart is


6
example is
Int i=1;
While(i<=5)
{
Printf(“%d”,i);
I++;
}
 example is
Int i=1;
do
{
Printf(“%d”,i);
I++;
}while(i<=5);

q36)Wap to display those records which have price >340. Records are with fields name,price and edition.

//Wap to display those records which have price >340. Records are with fields name,price and edition.
#include<stdio.h>
include<conio.h>
void main()
{
FILE *k;                                                                    //  pointer for file declaration
char book_name[30],author_name[40];                   //identifier declaration
int book_edition;                                                         //       "             "
k=fopen("book.dat","r");

while((fscanf(k,"%d %s %d",&book_price,book_name,&book_edition)!=EOF))//reading data from data file
{
 if(book_price>340)                                                   // condition validating
{
printf("book name=%s ,book edition=%d and price=%d",book_name,book edition,book_price); //displaying data
}
}
fclose(k);                                                                                   //closing data file
getch();
}