Skip to main content

C LANG LAB


Roots of Quadratic Equation

Algorithm:
Step 1: start
Step 2: Read the values of a, b, c and go to step3
Step 3: Is a=0 then go to step 4 otherwise go to step5
Step 4: Print the given equation is linear equation and go to step 11
Step 5: Compute d=(b*b)-(4*a*c)) and go to step 6
Step 6: Is d<0 then go to step7 otherwise go to step8
Step 7: Print the roots are imaginary and go to step 11
Step 8: Is d=o then go to step 9 otherwise go to step10
Step 9: Compute r and print the roots are real and equal lent to ‘r’ and go to step 11
Step 10: Is d >0 Then compute   and r2  , print r1, r2 and go to step11
Step 11: Stop

/* WAP in C To Find Roots of given Quadratic Equations*/

#include<stdio.h>
#include<math.h>
float d,r1,r2,r;
main( )
    {
      float a,b,c;
      clrscr();
      printf("\nENTER a, b, c VALUES OF QUDRATIC EQUATION\n");
      scanf("%f%f%f",&a,&b,&c);
      if( a==0)
             {
               printf("\nTHE GIVEN EQUATION IS LINEAR");
             }
             else
            {
                   d=(b*b)-(4*a*c);
                    if(d>0)
                        {
                           printf("\n ROOTS ARE UNEQUAL");
                            r1=((-b)+(sqrt(d)))/(2*a);
                            r2=((-b)-(sqrt(d)))/(2*a);
                            printf("\n ROOT1= %f\n ROOT2= %f",r1,r2);
                          }
                          else if(d<0)
                            {
                               printf("\n ROOTS ARE IMAGINERY AND COMPLEX");

                            }
                         else if(d==0)
                                    {
                                     printf("\n ROOTS ARE EQUAL");
                                     r=((-b)+(sqrt(d)))/(2*a);
                                     printf("\n ROOT= %f",r);
                                    }
                }
                getch( );

}

Output:

ENTER a, b, c VALUES OF QUADRETIC EQUATION
0
1
2
The given equation is linear


ENTER a, b, c VALUES OF QUADRETIC EQUATION
3
6
3
    roots are equal
    ROOT= -6.000000

ENTER a, b, c VALUES OF QUADRETIC EQUATION
1
2
3
    roots are IMAGINERY AND COMPLEX


 ENTER a, b, c VALUES OF QUADRETIC EQUATION
1
4
3
    roots are UNEQUAL
    ROOT1= -1.000000
    ROOT2= -3.000000

Calculate Area, Circumference, of Circle and Volume of Sphere & Hemisphere using Functions and Switch statement.
Algorithm:
Step1: Start
Step2: Read ch
Step3: Is ch=1 then go to step5 otherwise go to step 6
Step4: call aoc( )
Step5: Is ch=2 then go to step7 otherwise go to step 8
Step6: call coc( )
Step7: Is ch=3 then go to step 9 otherwise go to step 10
Step8: call vos(  )
Step9: Is ch=4 then go to step11 otherwise go to step 12
Step10: call vohs( )
Step11: print the entered choice not matched
Step12: stop
Algorithm for functions designing:
(1)aoc( ):
Step1: Start 
Step2 : Read r
Step3: Compute a = 3.141*(r*r)
Step4: Print a and go to step 5
Step5: Stop

(2)coc( ):
Step1: Start
Step2: Read r
Step3: Compute c=2*3.141*r
Step4: Print ‘c’ and go to step5
Step5: Stop

(3) vos( ):
Step1: Start
Step2: Read r
Step3: Compute v1 =(4/3)*(3.141)*(r*r*r)
Step4: Print v1 and go to step 5
Step5: Stop

(4) vohs():-
Step1: Start
Step2: Read r
Step3: Compute v2=(2/3)*3.141*(r*r*r)
Step4: Print v2 and go to step5
Step5: Stop
/* WAP in C to Calculate Area, Circumference, of Circle and Volume of Sphere & Hemisphere using Functions and Switch statement */

#include<stdio.h>
main( )
    {
     int choice;
     clrscr();
     printf("\tMAIN MENU\n");
     printf("\t---- ----\n");
     printf("\t1.AREA OF CIRCLE\n");
     printf("\t2.CIRCUMFRENCE OF CIRCLE\n");
     printf("\t3.VOLUME OF SPHERE\n");
     printf("\t4.VOLUME OF HEMI SPHERE\n");
     printf("\n\tENTER YOUR CHOICE:\n\t");
     scanf("%d",&choice);

     switch(choice)
               {
                case 1 :
                             aoc( );
                             break;
                case 2 :
                             coc( );
                             break;
                case 3 :
                             vos( );
                             break;
                case 4 :
                             vosh( );
                             break;
                default:
                             printf("\n\t ENTER VALID CHOICE");
                             break;
               }
     getch();
     }


aoc( )
       {
                int r,a;
                printf("\n\tENTER THE VALUE OF RADIUS:");
                scanf("%d",&r);
                a=(3.141*r*r);
                printf("\n\tTHE AREA OF CIRCLE IS:%d",a);
       }
 

  coc( )
       {
       int r,c;
       printf("\n\tENTER THE VALUE OF R:");
       scanf("%d",&r);
       c=(2*3.141*r);
       printf("\n\tTHE CIRCUMFRENCE OF CIRCLE IS: %d",c);
       }


   vos( )
       {
       int r,v1;
       printf("\n\tENTER THE VALUE OF R:");
       scanf("%d",&r);
       v1= ((4*3.141*r*r*r)/3);
       printf("\n\tTHE VOLUME OF SPHERE IS:%d",v1);
       }


   vosh( )
       {
       int r;
       float v2;
       printf("\n\tENTER THE VALUE OF R:");
       scanf("%d",&r);
       v2= ((2*3.141*r*r*r)/3);
       printf("\n\tTHE VOLUME OF HEMISPHERE IS:%f",v2);
       }

Output:

MAIN MENU
-------- ---------
1.AREA OF CIRCLE
2.CIRCUMFRENCE OF CIRCLE
3.VOLUME OF SPHERE
4.VOLUME OF HEMI SPHERE

ENTER YOUR CHOICE
1

ENTER THE VALUE OF R:3

THE AREA OF CIRCLE IS: 28


MAIN MENU
-------- ---------
1.AREA OF CIRCLE
2.CIRCUMFRENCE OF CIRCLE
3.VOLUME OF SPHERE
4.VOLUME OF HEMI SPHERE

ENTER YOUR CHOICE
2

ENTER THE VALUE OF R:2

THE CIRCUMFRENCE OF CIRCLE IS: 12

MAIN MENU
-------- ---------
1.AREA OF CIRCLE
2.CIRCUMFRENCE OF CIRCLE
3.VOLUME OF SPHERE
4.VOLUME OF HEMI SPHERE

ENTER YOUR CHOICE
3

ENTER THE VALUE OF R:2

THE VOLUME OF SPHERE  IS: 25

MAIN MENU
-------- ---------
1.AREA OF CIRCLE
2.CIRCUMFRENCE OF CIRCLE
3.VOLUME OF SPHERE
4.VOLUME OF HEMI SPHERE



ENTER YOUR CHOICE
4

ENTER THE VALUE OF R:4

THE VOLUME OF HEMISPHERE  IS: 134.016006


MAIN MENU
-------- ---------
1.AREA OF CIRCLE
2.CIRCUMFRENCE OF CIRCLE
3.VOLUME OF SPHERE
4.VOLUME OF HEMI SPHERE

ENTER YOUR CHOICE
6

ENTER THE VALID CHOICE



FIBBIONACCI SERIES
Algorithm:
Step 1: Start
Step 2: Read n
Step 3: Set  x=1,y=o,z=o
Step 4: While n≠o then go to step5 otherwise go to step 10
Step 5: Write z and go to step16
Step 6: Compute z=x+y , Set x=y and y=z and go to step 7
Step 7: Compute n=n-1 and go to step8
Step 8: Go to step4
Step 9: Repeat step 5 to step 7 until n reaches to 0 and go to step 10
Step 10: Stop


/* WAP in C to find Fibonacci up to given range */

#include<stdio.h>
main(  )
         {
          int n,z=0,x,y;
          clrscr( );
          printf("ENTER NUMBER\n");
          scanf("%d",&n);
          printf("FIBANOCII SERIES\n");
          printf("********* *******\n");
          x=1;
          y=0;
          z=0;
          while(n!=0)
                   {
                     printf("  %d",z);
                     z=x+y;
                     x=y;
                     y=z;
                     n=n-1;
                  }
     getch(  );
    }


Out put:

Enter number
9
FIBANOCII SERIES
********* ********
0  1  1  2  3  5  8  13  21


Enter number
5
FIBANOCII SERIES
********* ********
0  1  1  2  3    

Armstrong Number
 Algorithm:
Step 1: Start
Step 2: Read n
Step 3: Set rim=0, num, a=0, num=n

Step 4: While n≠0 then go to step5 otherwise go to step8

Step 5: Compute r=n%10, n = n/10, a= a+(rim * rim * rim)

Step 6: Is num= =a then print the given the number is Armstrong number and go to step8 otherwise go to step7
Step 7: Print the given number is not Armstrong
Step 8: Stop
/* WAP in C to find given number is Armstrong or not */

#include<stdio.h>
main( )
    {
     int n,rim=0,num,a=0;
     clrscr( );
     printf("ENTER NUMBER\n");
     scanf("%d",&n);
     num=n;
     while(n!=0)
              {
               rim=n%10;
               a= a+(rim * rim * rim);
               n=n/10;
              }
     num= =a ? printf("\n%d IS ARMSTRONG NUMBER",num): printf("\n%d IS NOT ARMSTRONG NUMBER",num);
     getch( );
    }


Output:

ENTER NUMBER
371
371 IS ARMSTRONG NUMBER


ENTER NUMBER
541
541 IS NOT ARMSTRONG NUMBER


Prime Number in given range.
Algorithm:
Step 1: Start
Step 2: Read n
Step 3: Repeat step 4 until i reaches to n
Step 4: Set dc=0, Repeat step 5 until j reaches to i
Step 5: Is i % j=0 then
             Set dc=dc+1, go to step 5  
Step 6: Is dc=2 then print i and go to step 3   
 Step 7: Stop

/* WAP in C to find Prime numbers up to given number */

#include<stdio.h>
main(  )
        {
         int n,i,j,dc=0;
         clrscr();
         printf("ENTER NUMBER\n");
         scanf("%d",&n);
         printf("\nPRIME NUMBERS\t");
         printf("\n***** *******\t");
         for (i=1;i<=n;i++)
               {
              dc=0;
              for(j=1;j<=i;j++)
                   {
                      if(i%j==0)
                         {
                          dc++;
                         }
                    }
              if(dc==2)
                {
                 printf("\n\t%d",i);
                }
             }
     getch(  );
    }



OUTPUT:

Enter number
10
PRIME NUMBER
****** ********
2
3
5
7

Enter number
15
PRIME NUMBER
****** ********
2
3
5
7
11
13




Perfect Number
Algorithm:
Step1: Start
Step2: Read n, i
Step3: Set p=0 and
Step4: Repeat step5 and steps6 until i<=n-1
Step5: Is n%i=o then  print the given number is perfect number and  go to step 10 otherwise go to step 7
Step6: Compute p=p+i
Step7: Go to step 4
Step8: Is p==n then print the given number is perfect number and go to step 10. Otherwise go to step 9
Step9: Print the given number is not a perfect number and go to step 10
Step10: Stop




/*WAP in c to find given number is perfect or  not*/

#include<stdio.h>
main( )
        {
          int n,i,p=0;
          clrscr( );
          printf("ENTER YOUR NUM\n");
          scanf("%d",&n);
          for(i=1;i<n;i++)
               {
              if(n%i==0)
                {
                  p=p+i;
                }
            }
          if(p==n)
                       {
                          printf("\n%d IS PERFECT NUMBER", n);
                        }
                 else
                        {
                            printf("\n%d IS NOT PERFECT NUMBER",n);
                         }
     getch( );
    }



Output:

ENTER YOUR NUM
6
6  IS PERFECT NUMBER


ENTER YOUR NUM
9
9  IS  NOT PERFECT NUMBER



Factorial using Recursion
Algorithm:
Step 1: Start
Step 2: Read n
Step 3: fact=factorial (n) 
Step 4: Print the factorial value of given number and fact.
Step 5: Stop

Algorithm for function designing:
Step 1: Is n=1 then go to step5. Otherwise go to step6
Step 2: Return the value “l”
Step 3: Compute fact=n*factorial (n-l)
Step 4: Return fact value



/*WAP in c to find Factorial of given number using Recursion*/

#include<stdio.h>
 main( )
         {
           int n,f=0;
           clrscr( );
          printf("ENTER NUMBER\n");
          printf("****** *********\n");
          scanf("%d",&n);
         f=fact(n);
         printf("\n\nFACTORIAL OF %d IS :  %d",n,f);
         getch( );
        }

int fact(int x)
            {
             if(x<1)
               {
                 return(1);
               }
               else
                   {
                         return(x*fact(x-1));
                   }
             }





OUT PUT:

ENTER NUMBER:
****** *********
5
FACTORIAL OF 5 IS : 120

ENTER NUMBER:
****** *********
7
FACTORIAL OF  IS :  5040




Biggest & Smallest elements in the array
Algorithm:
Step 1: Start
Step 2: Read length of array (number of elements placed in the array) and store this value in ‘n’
Step 3: Repeat step 4 ‘n’ times until ‘I’ reaches ‘n’ from ‘o’
Step 4: Read a[i]
Step 5: Set big=a[0]
                   small=a[0]
Step 6: Repeat step7 and step8 ‘n-1’ times where i=1 to ‘n-1’
Step 7: Is a[i]>big then place big=a[i]
Step 8: Is a[i]<small then place small=a[i]
Step 9: Print biggest and smallest elements placed in the array
Step 10: Stop


/* WAP in C to find BIGGEST AND SMALLEST NUMBER from given list of number */

#include<stdio.h>
main( )
    {
     int a[20],s,i,j,big,small;
     clrscr();
     printf("ENTER SIZE OF ARRAY\n");
     scanf("%d",&s);
     printf("ENTER NUMBERS IN ARRAY\n");
     for(i=1;i<=s;i++)
            {
            scanf("%d",&a[i]);
            }
     big = small = a[1];
     for(i=1;i<=s;i++)
             {
              if(big < a[i])
                {
                 big=a[i];
                }
              if(small > a[i])
                {
                 small=a[i];
                }
             }

      printf("\t\nTHE BIGGEST NUMBER IS: %d",big);
      printf("\t\nTHE SMALLEST NUMBER IS:%d",small);

     getch();
    }


OUTPUT:

ENTER THE SIZE OF ARRAY
5
ENTER NUMBERS IN ARRAY
15
65
98
63
65
THE BIGGEST NUMBER IS: 98
THE SMALLEST NUMBER IS: 15


ENTER THE SIZE OF ARRAY
8
ENTER NUMBERS IN ARRAY
5
65
98
63
65
102
980
15
THE BIGGEST NUMBER IS: 980
THE SMALLEST NUMBER IS: 5

Sorting Elements of array
Algorithm:
Step 1: Start
Step 2: Read length of array and place this value in n
Step 3: Read step 4 “n” times until ‘i’ reaches to n from ‘o’
Step 4: Print a[i]
Step 5: Repeat step6 for ‘n’ times until ‘i’ reaches to ‘n’ from ‘a’
Step 6: Print a[i]
Step 7: Repeat step8 for ‘n-1’ times until ‘i’ reaches to ‘n-1’ from ‘1’
Step 8: Repeat step9 for ‘n’ times until ‘j’ reaches to ‘n’ from ‘i+1’
Step 9: Is a[i]>a[j] then go to step 10 otherwise go to step 7
Step 10: Set t=a[i]
                   a[i]=a[j]
                   a[j]= t
Step 11: Repeat step 10 for n times until ‘I’ reaches to ‘n’ from ‘o’
Step 12: Print a [i ] and go to step 13
Step 13: Stop


/* WAP in C to Sorting Elements of array*/
#include<stdio.h>
main( )
    {
     int a[20],i,j,temp=0,n;
     clrscr(  );
     printf("ENTER SIZE OF ARRAY\n");
     scanf("%d",&n);
     printf("ENTER NUMBERS IN ARRAY\n");
     for(i=1;i<=n;i++)
            {
            scanf("%d",&a[i]);
            }
     printf("\nBEFORE SORTING NUMBERS\n");
     printf("\n****** ******* *******\n");
     for(i=1;i<=n;i++)
            {
            printf("%d\n",a[i]);
            }

     for(i=1;i<=n;i++)
             {
              for(j=i+1;j<=n;j++)
                 {
                  if(a[i] < a[j])
                         {
                           temp=a[i];
                           a[i]=a[j];
                           a[j]=temp;
                           }
                   }
              }
              printf("AFTER SORTING NUMBERS\n");
              printf("***** ******* *******\n");
              for(i=1;i<=n;i++)
                  {
                   printf("%d\n",a[i]);
                  }
     getch();
    }



OUTPUT:

ENTER SIZE OF ARRAY
5

ENTER NUMBERS IN ARRAY
12
65
36
54
98

BEFORE SORTING NUMBERS
******* ********* **********
12
65
36
54
98

AFTER SORTING NUMBERS
******* ******** *********
12
36
54
65
98

Find given Number from an array
Algorithm:

Step 1: Start
Step 2: Read length of array and place this value in s
Step 3: go to step 4 “n” times until ‘i’ reaches to n from ‘0’
Step 4: read a[i]
Step 5 : Read the number want to search n
Step 6 : go to step 7 “n” times until ‘i’ reaches to n from ‘0’
Step7 : Is a[i]=n than
              Set found=1 otherwise fount=0
Step 8: Is found=1 than
               Display number is found otherwise not found
Step 9: stop



/* WAP in C to Find given number from an array*/

#include<stdio.h>
main(  )
    {
     int a[20],i,s,n,found=0;
     clrscr(  );
     printf("ENTER SIZE OF ARRAY\n");
     scanf("%d",&s);
     printf("ENTER NUMBERS IN ARRAY\n");
     for(i=1;i<=s;i++)
            {
            scanf("%d",&a[i]);
            }
     printf("\nENTER NUMBER FOR SEARCHING\n");
     scanf("%d",&n);

     for(i=1;i<=s;i++)
            {
             if(n==a[i])
             found=1;
            }
            if(found==1)
               {
                printf("ELEMENT IS FOUND IN ARRAY\n");
               }
            if(found==0)
              {
               printf("ELEMENT IS NOT FOUND IN ARRAY\n");
              }
     getch(  );
    }


OUTPUT:

ENTER SIZE OF ARRAY
5
ENTER NUMBERS IN ARRAY
12
23
65
98
96

ENTER NUMBER FOR SEARCHING
98

ELEMENT IS FOUND IN ARRAY


ENTER SIZE OF ARRAY
5
ENTER NUMBERS IN ARRAY
12
23
65
98
96

ENTER NUMBER FOR SEARCHING
44

ELEMENT IS NOT FOUND IN ARRAY


Sum of Diagonal elements of Square Matrix
Algorithm:
Step 1: start
Step 2: Read number of rows and columns of matrix and store the values in r,c
Step 3: set sum=0
Step 4: Repeat step6 ‘n’ times until ‘I’ reaches to ‘n’ from ‘o’
Step 5:  Repeat step6 ‘m’ times until j reaches to m from ‘o’
Step 6: Read a[i] [j]
Step 7: r=c then go to step8 otherwise go to step 12
Step 8: Repeat step10 until ‘i’ reaches to ‘r from ‘o’
Step 9: repeat step10 until ‘j’ reaches to c from ‘o’
Step 10: Is i=j then
               Compute sum=sum+a[i][j] otherwise go to step8     
Step 11: Display sum and go to step 13
Step 12: Print the given matrix is not square matrix and go to step 13
Step 13:  stop


/* WAP in C to find Sum of Diagonal of Square Matrix */

#include<stdio.h>
main()
    {
     int a[5][5], r,c,i,j,sum=0;
     clrscr( );
     printf("ENTER SIZE OF MATRIX:\n");
     scanf("%d%d" ,&r,&c);
     if((r==c)
       {
         printf("ENTER ELEMNTS OF MATRIX\n");
         for(i=0;i<r;i++)
            {
            for(j=0;j<c;j++)
               {
                scanf("%d",&a[i][j]);
               }
            }
             printf("SUM OF DIGONAL OF MATRIX IS:");
            for(i=0;i<r;i++)
               {
                for(j=0;j<c;j++)
                   {
                       if( i == j)    sum= c[i][j] +a[i][j];
                   }
                }
             
            printf("   %d",sum);
     }
      else
            {
                printf("MATRIX IS NOT SQUARE MATRIX");
            }

    getch();
}



OUTPUT:

ENTER SIZE OF MATRIX:
2
2
ENTER ELEMNTS OF MATRIX
1
2
3
4
SUM OF DIGONAL OF MATRIX IS: 6



ENTER SIZE OF MATRIX:
2
3

MATRIX IS NOT SQUARE MATRIX


Matrix Multiplication
Algorithm:
Step 1: Start
Step 2: Read number of rows and columns of first matrix and store the values in r1,c1
Step 3: Repeat step4 and step5 until i reaches to ‘r1’ from ‘0’
Step 4: Repeat step5 until j reaches to ‘c1’ from ‘0’
Step 5: Read a[i][j]
Step 6: Read number of rows and columns for second matrix and store them in r2, c2
Step 7: Repeat step8 and step9 until i reaches to ‘r2’ from ‘0’
Step 8: Repeat step9 until j reaches to ‘c2’ from ‘0’
Step 9: Read b[i][j]
 Step 10: Is c2=r1 then go to step11 otherwise go to step 19
Step 11: Repeat step12 to step15 until i reaches to ‘r1’ from ‘0’
Step 12: Repeat step13 to step 15 until j reaches to ‘c2’ from ‘0’
Step13: Set c[i][j]=o
Step14: Repeat step15 until k reaches to ‘c1’ from ‘0’
Step15: Compute c[i][j]=c[i][j]+a[i][k]*b[k][i]
Step16: Repeat step17 and step 18  until i reaches to ‘r1’ from ‘0’
Step17: Repeat step18 until j reaches to ‘c2’ from ‘0’
Step18: Print c[i][j] and go to step20
Step19: Matrix multiplication is not possible and goes to step 20
Step 20: Stop


/* WAP in C to Find Multiplication of two Matrix */

#include<stdio.h>
main( )
    {
     int a[5][5],b[5][5],c[5][5],r1,c1,r2,c2,k,i,j;
     clrscr( );
     printf("ENTER SIZE OF FIRST(A) MATRIX:\n");
     scanf("%d%d" ,&r1,&c1);
     printf("ENTER ELEMNTS OF FIRST(A) MATRIX\n");
     for(i=0;i<r1;i++)
            {
            for(j=0;j<c1;j++)
               {
                scanf("%d",&a[i][j]);
               }
            }
     printf("ENTER SIZE OF SECOND(B) MATRIX:\n");
     scanf("%d%d" ,&r2,&c2);
     printf("ENTER ELEMENTS OF SECOND(B) MATRIX\n");
     for(i=0;i<r2;i++)
            {
            for(j=0;j<c2;j++)
               {
                scanf("%d",&b[i][j]);
               }
            }

     if(c1==r2)
       {
            printf("MATRIX MULTIPLICATION IS POSSIBLE\n");
            printf("RESULTANT MATRIX IS:\n");
            for(i=0;i<r1;i++)
               {
                for(j=0;j<c2;j++)
                   {
                        c[i][j]=0;
                        for(k=0;k<r1;k++)
                            {
                            c[i][j] = c[i][j]+(a[i][k]*b[k][j]) ;
                            }
                   }
                }
            for(i=0;i<r1;i++)
            {
            for(j=0;j<c2;j++)
               {
                printf("   %d",c[i][j]);
               }
            printf("\n");
            }
            }
           

        else
            {
            printf("MATRIX MULTIPLICATION IS NOT POSSIBLE");
            }

    getch( );
}




OUTPUT:

ENTER SIZE OF FIRST(A) MATRIX:
 2
2
ENTER ELEMNTS OF FIRST(A) MATRIX
1
2
3
4
ENTER SIZE OF SECOND(B) MATRIX:
2
1

ENTER ELEMENTS OF SECOND(B) MATRIX
 7
8

MATRIX MULTIPLICATION IS POSSIBLE
RESULTANT MATRIX IS:
23
53

String Functions
Algorithm:

Step 1: Start
Step 2: Read input strings into s1,s2
Step 3: Compute length of string s1
 Step 4: Concate s1 and s2 save on s1, display s1
 Step 5: Convert string s1 into lower case and display s1
Step 6: Convert string s2 into upper case and display s2
 Step 7: Reverse the string s1 and save on s1 and display s1
Step 8: Copy s2 into s1 and display s1
Step 9: Stop


/* Program to Demonstrate String Functions in C Language*/

#include<stdio.h>
#include<string.h>
main( )
    {
     char s1[100],s2[100];
     clrscr( );
     printf("ENTER STRINGS\n");
     gets(s1);
     gets(s2);
     printf("\nSTRING OPERATIONS USING STRING FUNCTIONS\n\n");
     puts("LENGTH OF STRING S1 IS: ");
     printf("%d",strlen(s1));
     puts("\nCONCATING OF S1 AND S2 IS: ");
     strcat(s1,s2);
     puts(s1);
     puts("\nLOWER CASE OF STRING S1 IS: ");
     strlwr(s1);
     puts(s2);
     puts("\nUPPER CASE OF STRING S2 IS: " );
     strupr(s2);
     puts(s2);
     puts("\n\nREVERSE OF STRING S1 IS: ");
     strrev(s1);
     puts(s1);
     strrev(s1);
     puts("\nCOPYING S2 INTO S1: ");
     strcpy(s1,s2);
     puts(s1);
     getch( );
    }


OUTPUT:

ENTER STRINGS

computer
science

STRING OPERATIONS USING STRING FUNCTIONS

LENGTH OF STRING S1 IS:
9

CONCATING OF S1 AND S2 IS:
COMPUTER science

UPPER CASE OF STRING S2 IS:
SCIENCE

LOWER CASE OF STRING S1 IS:
computer

REVERSE OF STRING S1 IS:
retupmoc

COPYING S2 INTO S1:
SCIENCE



String Palindrome
Algorithm:
Step 1: Start
Step 2: Read input string into ‘s1’
Step 3: Set s2=null
 Step 4: Reverse s1 and save on s2
 Step 5: Is s1=s2 then go to step 6 otherwise go to step 7
Step 6: Print the given string is palindrome and go step 8
Step 7: Print the given string is not a palindrome and go to step 8
Step 8: stop




/*Write a C Program to Find Given String is Palindrome or not*/

#include<stdio.h>
#include<string.h>
main( )
    {
     char s1[100],s2[100];
     int i;
     clrscr();
     printf("ENTER STRING S1\n");
     gets(s1);
     strcpy(s2,s1);
     puts("\n\nREVERSE OF STRING S1 IS: ");
     strrev(s1);
     
     if(strcmp(s1,s2)==0)
            {
             printf("\n%s IS PALINDROM",s2);
            }
       else
              {
               printf("\n%s IS NOT PALINDROM",s2);
              }
     getch( );
    }

OUTPUT:

ENTER STRINGS
computer

REVERSE OF STRING S1 IS:
retupmoc
computer  IS NOT PALINDROM



ENTER STRINGS
amma

REVERSE OF STRING S1 IS:
amma
amma IS PALINDROM

Pointers
Algorithm:

Step 1: Start
Step 2: Read *p, *q, *r
Step 3: Set a=10, b=20, c=0
 Step 4: Set a=*p, b=*q, c=*r
 Step 5: Compute *r = *p +*q
Step 6: Print address of a is p, Print value of a is *p
 Step 7: Print address of b is q, Print value of b is *q
Step 8: Print address of c is r, Print value of c is *r
Step 9: Stop


/*Program to Demonstrate Pointers in C Language*/

#include<stdio.h>
main(  )
         {
           int a=10, b=20, c=0;
           int *p,*q,*r;
          clrscr(  );
          p=&a;
          q=&b;
          r=&c;
         *r=*p+*q;
         printf("\n\n a=%d",a);
         printf("\n\n address of a=%u",p);
         printf("\n\n b=%d",b);
         printf("\n\n address of b=%u",q);
         printf("\n\n c=%d",c);
         printf("\n\n address of c=%u",r);
         printf("\n\n final result");
         printf("\n\n%d",*r);
         getch (  );
       }



OUTPUT:

a = 30

address of a = 65486
b = 20

address of a = 65488
c = 30

address of a = 65490

final result
30




Design “Student Profile’’ using Structures
Algorithm:
Step 1: Start
Step 2: Define structure with name ‘faculty’
Step 3: Declare the members of structure as follows.
Step 4: (1) roll as integer
            (2) name as character
            (3)cls as character
            (4) fee as float
Step 5: Declare structure variable stu[10]
Step 6: Read ‘n’ for strength of faculty
Step 7: Repeat step8 to step11 until ‘i’ reaches to ‘n’ from ‘0’
Step 8: Read stu[i].roll
Step 9: Read stu[i].name
Step 10: Read stu[i].cls
Step 11: Read stu[i].fee
Step 12: Repeat step13 to step16 until ‘i’ reaches to ‘n’ from ‘0’
Step 13: Print stu[i].roll
Step 14: Print stu[i].name
Step 15: Print stu[i].cls
Step 16: Print stu[i].fee
Step 17:-stop
/*WAP in C to Create Structure for Student Profile*/

#include<stdio.h>
#include<string.h>
main(  )
    {
    int n,i;
    struct studet
                        {
                        int roll;
                        char name[20];
                        char cls[5];
                        int fee;
                        };
    struct studet stu[10];
    clrscr(  );
    printf("ENTER NUMBER OF STUDENTS\n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
       {
            printf("\n ENTER %d STUDENT DETAIL", i);
            puts("\nROLL:");
            scanf("%d",&stu[i].roll);
            puts("\nNAME:");
            scanf("%s",stu[i].name);
            puts("\nCLASS:");
            scanf("%s",stu[i].cls);
            puts("\nFEE:");
            scanf("%d",&stu[i].fee);
       }

    for(i=1;i<=n;i++)
       {
            printf("\n %d STUDENT DETAIL",i);
            printf("\nROLL:%d",stu[i].roll);
            printf("\nNAME:%s",stu[i].name);
            printf("\nCLASS:%s",stu[i].cls);
            printf("\nFEE:%d",stu[i].fee);
       }
     getch();
    }




Output:

ENTER NUMBER OF STUDENTS
5
ENTER 1 STUDENT DETAIL
ROLL:
01
NAME:
satish
CLASS:
b.sc
FEE:
45000
ENTER 2 STUDENT DETAIL
ROLL:
02
NAME:
lakshman
CLASS:
b.com
FEE:
25000
ENTER 3 STUDENT DETAIL
ROLL:
03
NAME:
d.v.v.satish
CLASS:
bba
FEE:
35000
ENTER 4 STUDENT DETAIL
ROLL:
04
NAME:
sarma
CLASS:
bca
FEE:
25000
ENTER 5 STUDENT DETAIL
ROLL:
05
NAME:
durga rao
CLASS:
b.sc
FEE:
15000

1 STUDENT DETAIL
ROLL: 01
NAME: satish
CLASS: bba
FEE:35000
2 STUDENT DETAIL
ROLL: 02
NAME: lakshman
CLASS: b.com
FEE:25000
3 STUDENT DETAIL
ROLL: 03
NAME: d.v.v.satish
CLASS: bba
FEE:35000

4 STUDENT DETAIL
ROLL: 04
NAME: sarma
CLASS: bca
FEE:25000
5 STUDENT DETAIL
ROLL: 05
NAME: durgarao
CLASS: b.sc
FEE:15000

















Operations on Files
Algorithm:
Step 1: Start
Step 2: Open the file in “write mode”
Step 3: Read some text into the file until the file is end
Step 4: Close the file
Step 5: Open the file in read mode
Step 6: Display the information placed on files
Step 7: Close the file
Step 8: Stop


/*WAP in C to Create File of Student Details*/

#include<stdio.h>
#include<string.h>
main( )
    {
    FILE *fp;
    int roll[20],n,i;
    char name[20][20];
    char cls[5][5];
    clrscr();
    fp=fopen("d:\\sridhar\\clab\\final\\studet.doc","w+");
    printf("ENTER NUMBER OF STUDENTS\n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
       {
            printf("\n ENTER %d STUDENT DETAIL", i);
            puts("\nROLL:");
            scanf("%d",&roll[i]);
            fprintf(fp,"\n%d",roll[i]);
            puts("\nNAME:");
            scanf("%s",name[i]);
            fprintf(fp,"\t%s",name[i]);
            puts("\nCLASS:");
            scanf("%s",cls[i]);
            fprintf(fp,"\t%s",cls[i]);
       }
    printf("\n STUDENT DETAIL");
    printf("\nROLL\tNAME\tCLASS");
    if(fp==NULL)
      {
      printf("\nOOPS NO DATA\n");
      }
      else
             {
              for(i=1;i<=n;i++)
                 {
                  fscanf(fp,"%d",&roll[i]);
                  fscanf(fp,"%s",name[i]);
                  fscanf(fp,"%s",cls[i]);
                  printf("\n%d\t%s\t%s",roll[i],name[i],cls[i]);
                 }
       }
     fclose(fp);
     getch();
    }








OUTPUT:

ENTER NUMBER OF STUDENTS
5
ENTER 1 STUDENT DETAIL
ROLL:
1
NAME:
satish
CLASS:
b.sc
ENTER 2 STUDENT DETAIL
ROLL:
2
NAME:
lakshman
CLASS:
b.com

ENTER 3 STUDENT DETAIL
ROLL:
3
NAME:
d.satish
CLASS:
bba

ENTER 4 STUDENT DETAIL
ROLL:
4
NAME:
sarma
CLASS:
bca

ENTER 5 STUDENT DETAIL
ROLL:
5
NAME:
durgarao
CLASS:
b.sc

FILE CREATED ATd:\\sridhar\\clab\\final\\studet.doc”

1          satish                b.sc
2          lakshman         b.com
3          d.satish                         bba
4          sarma                bca
5          durgarao          b.sc


















Comments

  1. Though the technical glitch scared a lot of people. It was just a publicity stunt to make the event even more interesting. The intention was good the question is. Is it necessary to make a fuss just before the big event? I don't think so.jogos friv gratis 2019
    Jogos 2019
    jogos friv
    abcya free games only

    ReplyDelete

  2. https://www.codeninja.pk

    A lot of people do not know how to do all this so they hire web development companies or experts. web development Company is offering its services for web development for new and old businesses.

    ReplyDelete
  3. Have you ever thought about adding a little bit more than just your articles? I mean, what you say is valuable and all. But just imagine if you added some great visuals or video clips to give your posts more, "pop"! Your content is excellent but with pics and videos, this website could certainly be one of the best in its niche. Very good blog!
    managed it support perth

    ReplyDelete

Post a Comment

Popular posts from this blog

Characteristics of computers

    Characteristics:        All computers have similar characteristics, which tells how computers are efficient to perform task. Computers have some Limitations also. Speed:     Computer can work very fast. It takes only few seconds for calculations on very large amount of data. Computer can perform millions (1,000,000) of instructions per second.      We measure the speed of computer in terms of microsecond (10-6 part of a second) or nanosecond (10 to the power -9 part of a second).   Accuracy:        The degree of accuracy of computer is very high and every calculation is performed with the same accuracy.  The errors in computer are due to human and inaccurate data.       The calculation done by computer are 100% error free, If we provide accurate input. Diligence:        A computer is free from tiredness, lack of concentration...

DS LAB FOR II YEAR

1.SINGLE LINKED LIST Procedure for creation of single linked list: STEP-1 : Declaring a variable named as “item”.Ie the element what we place in the linkedlist of the new node.         STEP-2 : Read the value   in “item”. Set first=last=null and next=null. STEP-3: Create a new node named as temp and assign the variable item to data part andassign Address of the node temp to null.       temp.data=item;       temp.next=null; STEP-4: Check   the address part of the first node Check if first=null Then assign first=last=temp Other wise Then assign the new node tolast.next=temp          last=temp STEP-6 : Repeat STEP-3 until you read required nodes. Procedure for display the linked list: STEP-1 : Check whether the list having nodes or not i.e Check if first=null        ...

LEVELS AND CURVES

LEVELS:                 Levels are used to set the shadows, mid tone etc.  O pen an image on Photoshop window. Select image menu on menu bar than adjustments than levels. A dialogue box will appear on screen which shows three pointers which indicates three optimum. The black triangle indicates shadows and gray triangle indicates mid tone and white triangle indicates highlights. In the channel menu different options are provided in drop down list. Make sure select on preview, which gives current adjustments on your picture. CURVES: Curves are to  similar to levels, it gives more power to control shadows highlights and mid tones. One of the simplest adjustment we can make with curves is increasing the contrast. Go to image menu and than adjustments,than curves. Dialogue box will appear on screen with straight diagonal line.      ...