Ques1.
Write a program to check number is prime or
note?
Ans.
#include<stdio.h>
int main()
    {
int i,n,count=0;
printf("enter the number");
scanf("%d",&n);
for( i=1;i<=n;i++)
{
if(n %i == 0)
    {
    count==2;
    }
}
if(count == 2)
    printf(" prime number");
else {
    printf("it is not a prime number");
}
}
Ques 2. Difference b/w break and continue using
examples?
Break                        continue
  1. Break is used to break    1. It is used to continue
      loop or iteration           the loop or iteration
   2. Used with switch         2. Not used with switch
      case.                       case.
   3. Control is transferred   3. Control remains same
      outside the loop.           inside the loop.
   4. Keyword break Is         4. Keyword continue Is
    used in break                             used in continue
    statement                                 statement
Example:-                                Example:-
#include<stdio.h>                        #include <stdio.h>
int main()
{
       int a,b,result;                   int main() {
       char n;
       printf("choose the                 int i;
option(+,-,*,/)\n");
       scanf("%c",&n);                       for (i = 0; i < 10; i++) {
       printf("enter two numbers\n");          if (i == 4) {
       scanf("%d %d",&a,&b);
switch(n){                                       continue;
       case'-':                                }
       result=a-b;
       break;
                                               printf("%d\n", i);
       case'+':                              }
       result=a+b;                       }
       break;
       case'*':
       result=a*b;
       break;
       case'/':
       result=a/b;
       break;
}
printf("your answer is %d \n",result);
}
b.
Ques. Difference b/w getch, getchar and getchc?
Ans. Getch:-reads a single character from the user at
the consol.
Getchar:- reads a single character from the user at the
consol.
Getche:- it will accept a keyword from keyboard and
displays it immediately.
Gets:-accept a string until enter key hits.
Ques. Write the difference b/w call by value and call
by reference?
Call by value                 Call by reference
1.this is case passing        1. this is case passing
value for variable.           value for address of a
                              variable .
2. no pointers are used.      2. pointers are used.
3.can’t change the value      3. Can change the value of
of original argument by       original argument by
formal argument.              formal argument.
4.it requires more            4. it requires less
memory.                       memory.
   5. It is less efficient.      5.It is more efficient.
Ques. Write different types of loops and explain them?
Ans. 1. While loop
     2. do while loop
     3. for loop
While loop: - while loop is pre-test loop.
             It is entry control loop.
It tests the condition before executing in the loop
body.
There is no semicolon.
Do while loop: -it is post-test loop.
               It is exit control loop.
     It tests the condition at the end of the loop body.
Semicolon is compulsory at the end of the loop.
For loop: - for loop is used to execute a set of
statements repeatedly until a particular condition is
satisfied.
we can say it an open ended loop.
Example:-
#include<stdio.h>
int main()
{
        int n,i,j;
        char alphabet='a';
        printf("enter the number");
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
        for(j=1;j<=i;j++){
               printf("%c",alphabet);
       }
                ++alphabet;
       printf("\n");
       }
       }
If-else                                      switch
1.if-else is a selection                      1. It is multiple choice
statement.                                           selection statement.
2.it can test any type of                      2.    It can test only integer and
expression.                                          character expression.
3.the execation of this                        3.    Execuation of statement is
statement depends upon the                           decided by the user.
code inside if.
4.it use multiple curly brasses                4.    It use only one curly brasses
{}.                                                  {}.
Eg: -
      #include<stdio.h>
      int main(){
                                             Eg: -
                                                 #include<stdio.h>
             int a,b,c;                          int main()
                                                 {
       printf("enter the first number\n");                int a,b,result;
       scanf("%d %d %d",&a,&b,&c);                        char n;
      if(a>=b && a>=c){                                   printf("choose the option(+,-,*,/)\n");
                                                          scanf("%c",&n);
      printf("%d",a);                                     printf("enter two numbers\n");
      }                                                   scanf("%d %d",&a,&b);
                                                 switch(n){
      else if(b>=a && b>=c){                              case'-':
      printf("%d",b);                                     result=a-b;
      }                                                   break;
                                                          case'+':
      else if(c>=b && c>=a){                              result=a+b;
      printf("%d",c);                                     break;
                                                          case'*':
      }                                                   result=a*b;
}                                                         break;
                                                          case'/':
                                                          result=a/b;
                                                          break;
                                                 }
                                             printf("your answer is %d \n",result);}
#include<stdio.h>
int main()
{
       int n,i,j;
       char alphabet='a';
       printf("enter the number");
       scanf("%d",&n);
       for(int i=1;i<=n;i++){
       for(j=1;j<=i;j++){
                    printf("%c",alphabet);
          }
                  ++alphabet;
          printf("\n");
          }
          }
(a).prime or not?
#include<stdio.h>
int main()
{
           int n,i,count=0;
           printf("enter the number");
           scanf("%d",&n);
           for(i=1;i<=n;i++){
                      if(n%i==0){
                                count++;
                      }
           }
           if(count==2)
           printf("number is prime\n");
           else
           printf("not prime\n");
}
(b).factorial of a given number?
#include<stdio.h>
int main(){
      int i,n,f=1;
      printf("enter the number\n");
      scanf("%d",&n);
      for(i=1;i<=n;i++){
              f=f*i;
              printf(" factorial of %d is%d\n",n,f);
      }
}
Ques:- write a program to generate fabonacci series?
Ans-
#include<stdio.h>
int main()
{
        int n,a=0,b=1,c,i;
        printf("enter the number of terms");
        scanf("%d",&n);
        for(i=1;i<=n;i++){
                 printf("%d\n",a);
                 c=a+b;
                 a=b;
                 b=c;
        }
        }
#include<stdio.h>
int main()
{
        int i,j,n;
        printf("enter the number");
        scanf("%d",&n);
        for(i=1;i<=n;i++){
                   for(j=1;j<=i;j++)
                            printf("%d",j);
           printf("\n");;
        }
}
Ques:- greatest number among the three?
#include<stdio.h>
int main(){
       int a,b,c;
 printf("enter the first number\n");
 scanf("%d %d %d",&a,&b,&c);
if(a>=b && a>=c){
printf("%d",a);
}
else if(b>=a && b>=c){
printf("%d",b);
}
else if(c>=b && c>=a){
printf("%d",c);
}
}
                                 Unit -2
Ques1. write down benefits using functions in c?
Ans.1. avoid repitation of codes.
     2. reduces program size.
     3. modifying a program becomes easier.
     4.reduces the chances of error.
     5.divides a complex problem into simpler once.
     6.easier to write and maintain.
     7. improves reuseability.
Ques2. What are storage classes in c?
Ans. 1. the storage class determine the part of the    memory where the
variable would be stored.
    2.the storage class also determine the intial value of the variable
    3.there are two storage location computer cpu registers and memory.
    4. there are four types of storage classes in c.
    -automatic storage class
    -register storage class
    -static storage class
    -external storage class
                                 Unit-3
Ques1:macros
Ans: macro substitutuion is a process where an
identifies in program is replaced by pre defined string
composed of one or more programs.
-simple macro substitution.
-argumented macro substitution.
-nested macro substitution.
Ques2: difference b/w text files and binary files?
Ans:
Text files                    Binary files
1.stores information in       1.stores the data in the
unicode chararcter.           same way as stored in the
                              memory.
2. each line is terminated    2.there is no delimetre for
by a special EOL              the new line.
chararcter
3.stores plain text in a file. 3.stores different types of
                               data like image,audio,text
4.can be directly read.        4.cannot be directly read.
5.sequental access.            5.random access.
Nested structure:-
-nested structure in c is structure in structure.
-one structure can be declared inside.
-the structure variable can be normal structure
variable.
File handling:-
                  Unit-4
String handling funcations:-