-->

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();
}

NEB35:WAP top read all records stored in a file book.dat. Fields are name,price and author's name.

//WAP top read all records stored in a file book.dat. Fields are name,price and author's name.
#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_price;                                                         //       "             "
k=fopen("book.dat","r");

while((fscanf(k,"%d %s %s",&book_price,book_name,author_name)!=EOF))//reading data from data file
{
printf("book name=%s ,author name=%s and price=%d",book_name,author_name,book_price); //displaying data
}
fclose(k);                                                                                   //closing data file
getch();
}

NEB34:WAP to store details about book(any 'n') having fields name,price,edition.

//WAP to store details about book(any 'n') having fields name,price,edition.
#include<stdio.h>
include<conio.h>
void main()
{
FILE *k;                                                                    //  pointer for file declaration
char book_name[30],choice;                                                    //identifier declaration
int book_price,edition;                                             //       "             "
k=fopen("book.dat","w");
do
{
printf("enter book's name\n");                                       // getting inuts
gets(book_name);
printf("enter edition\n");
scanf("%d",&edition);
printf("enter book's price\n");
scanf("%d",&book_price);
fprintf(k,"%s %d %d",book_name,edition,book_price);   //writing data to data file
printf("want to continue y/n\n");
choice=getche();                                                        //getting a character from user  
}while(choice!='n');                                                      // validating the input
printf("writing process completed successfully\n");
fclose(k);                                                                                   //closing data file
getch();
}

NEB33":WAP to store book's name,price and author's name in a file namd 'book.dat'.

//WAP to store book's name,price and author's name in a file named 'book.dat'.
#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_price;                                                         //       "             "
k=fopen("book.dat","w");
printf("enter book's name and author's name\n");   // getting inuts
gets(book_name);
printf("enter author's name\n");
gets(author_name);
printf("enter book's price\n");
scanf("%d",&book_price);
fprintf(k,"%s %s %d",book_name,author_name,book_price);   //writing data to data file
printf("writing process completed successflly\n");
fclose(k);                                                                                   //closing data file
getch();
}