Thursday, 26 April 2018

Program to Perform Linear Search Using C

Program :-


#include<stdio.h>
int A[100];
int linrsrch(int n,int item)  //Function to perform Linear search
{
     int i=0;
     while(i<n && A[i]!=item)  //Searching starts
                 i+=1;
     if(i==n)  //Returning values
                  return -1;
     else
                  return i;
}
void main()
{
    int n,i,item,pos;
    printf("Enter the array size");  //Reading the array size
    scanf("%d",&n);
    printf("Enter the array elements");  //Reading the array elements
    for(i=0;i<n;++i)
               scanf("%d",&A[i]);
    printf("Enter the item to be searched");  //Reading the item to be searched
    scanf("%d",&item);
    pos=linrsrch(n,item);   //Finding position of the item
    if(pos==-1)   //Printing not found if found else position
            printf("Item not found");
     else
            printf("The item %d is found at the position %d",item,pos+1);
}


Output :-

Eg 1:-Enter the array size : 5
Enter the array elements  : 32 45 18 25 56
Enter the item to be searched : 23
Item not found

Eg 2:-
Enter the array size : 5
Enter the array elements  : 32 45 18 25 56
Enter the item to be searched : 18
The item 18 is found at the position 3


Saturday, 8 April 2017

C Program to Print Fibonacci Series up to a Limit

Program :-
#include <stdio.h>
main() {
    int c,f1=0,f2=1,f,count ;
    printf("enter the limit : \n");
    scanf("%d",&c);
    printf("0 1");
    for(count = 3;count <= c; count ++)
    {
         f = f1 + f2;
         printf("%d\t",f);
         f1 = f2;
         f2 = f;
     }
}
       
Output :-

enter the limit :
5
0 1 1 2 3

Algorithm to Print Fibonacci Series up to a Limit

Step 1 : Start
Step 2 : Read Limit
Step 3 : Print 0 1
Step 4 : f1 = 0,f2 = 1 ,c = 1
Step 5 : if c <=  Limit  ,then go to Step 6 
             else go to Step 11
Step 6 : f = f1 + f2
Step 7 : print f
Step 8 : f1 = f2
Step 9 : f2 = f
Step 10 : c = c + 1 go to Step 5 
Step 11 : Stop

C Program to Calculate Area of a Square


Program :- 

#include<stdio.h>
main()
{
   float len,area;
   printf("enter length : \n");
   scanf("%f ",&len);
   printf("area =  %f ", len * len);
}
 
Output :-

enter length :
6

area = 36

C Program to Calculate Area of a Rectangle


Program :-

#include<stdio.h>
main()
{
   float b,l,area;
   printf("enter the breadth and the length : \n");
   scanf("%f %f ",&b,&l);
   printf("area =  %f ", b * l);
}

Output :- 

enter the breadth and length :
3
4
area = 12

C Program to Find Area of Circle


Program :-

#include<stdio.h>
main()
{
   float radius,area;
   printf("enter the radius : \n");
   scanf("%f",&radius);
   printf("area =  %f " ,3.14*radius*radius);
}
 
Output :-

enter the radius : 3
area = 28.26




C Program to Find Area of a Triangle


Program :-

#include <stdio.h>
#include <math.h>
main()
{
   float x,y,z,s,area;
   printf("enter sides ");
   scanf("%f %f %f ",&x,&y,&z);
   s = (x + y + z) / 2 ;
   printf("area =  %f ", sqrt(s*(s - x)*(s - y)*(s-z)) );
}
 
Output :-

enter sides :
4  4  2
area = 3.87


How to Invert an SVG image using CSS ?

You can invert your svg easily by using following css code svg { -webkit-filter: invert(100%); /* safari 6.0 - 9.0 */ filter...