Friday, November 24, 2017

Check two string weather they are same or not

///Check 2 string weather they are same or not
#include<stdio.h>
void main()
{
    int i,light=0;
    char s1[100],s2[100];
    gets(s1);///we
    gets(s2);///are
    if(strlen(s1)!=strlen(s2))
        printf("not same \n");
    else
    {
        for(i=0;s1[i]!=NULL;i++)
        {
            if(s1[i]!=s2[i])
            {
                light=1;
                break;
            }
        }
        if(light==1) printf("not same");
        else if(light==0)printf("same");
    }
}

Check Palindrome

Check Palindrome :

#include<stdio.h>
void main()
{
    int i,light=0;
    char s1[100],s2[100];
    gets(s1);///we
    strcpy(s2,s1);
    strrev(s2);///s2=ew
    if(strlen(s1)!=strlen(s2))
        printf("not palindrome \n");
    else
    {
        for(i=0;s1[i]!=NULL;i++)
        {
            if(s1[i]!=s2[i])
            {
                light=1;
                break;
            }
        }
        if(light==1) printf("not palindrome");
        else if(light==0)printf("palindrome");

    }
}

Tuesday, April 4, 2017

Structure using Array(students Information)

#include<stdio.h>

struct anything ///44 B
{
    int age;    ///4 B
    char name[20]; ///20 B           ///member definition
    char dept[10];///20 B

};

typedef struct anything newType ;



main()
{
    printf("Enter student number ");
    int num;
    scanf("%d",&num);
    newType student[num];
    int i;
    for(i=0 ; i<num ; i++)
    {
        printf("         Info of student %d : \n",i+1);

        printf("Name = ");
        getchar();
        gets(student[i].name);
        printf("Age = ");
        scanf("%d",&student[i].age);
        printf("Dept = ");
        getchar();
        gets(student[i].dept);
    }



    for(i=0 ; i<num ; i++)
    {
        printf("         Info of student %d : \n",i+1);

        printf("Name = ");
        puts(student[i].name);
        printf("Age  = %d\n",student[i].age);
        printf("Dept = ");
        puts(student[i].dept);
    }



}

Structure using function (students management system)

#include<stdio.h>

struct anything ///44 B
{
    int age;    ///4 B
    char name[20]; ///20 B           ///member definition
    char dept[10];///20 B

};

typedef struct anything newType ;


void display(int num,int i,newType student[])
{
        printf("         Info of student %d : \n",i+1);

        printf("Name = ");
        puts(student[i].name);
        printf("Age  = %d\n",student[i].age);
        printf("Dept = ");
        puts(student[i].dept);
}
main()
{
    printf("Enter student number ");
    int num;
    scanf("%d",&num);
    newType student[num];
    int i;
    for(i=0 ; i<num ; i++)
    {
        printf("         Info of student %d : \n",i+1);

        printf("Name = ");
        getchar();
        gets(student[i].name);
        printf("Age = ");
        scanf("%d",&student[i].age);
        printf("Dept = ");
        getchar();
        gets(student[i].dept);
    }



    for(i=0 ; i<num ; i++)
    {
       display(num,i,student);
    }



}

Structure with example of typedef

#include<stdio.h>

 struct anything ///44 B
{
    int age;    ///4 B
    char name[20]; ///20 B           ///member definition
    char dept[10];///20 B

};

 typedef struct anything newType ;

  newType student1,student2 ;

main()
{
    printf("         Info of student 1 : \n");

    printf("Name = ");
    gets(student1.name);
    printf("Age = ");
    scanf("%d",&student1.age);
    printf("Dept = ");
    getchar();
    gets(student1.dept);




    printf("Name = ");
    puts(student1.name);
    printf("Age  = %d\n",student1.age);
    printf("Dept = ");
    puts(student1.dept);





    printf("         Info of student 2 : \n");

    printf("Name = ");
    gets(student2.name);
    printf("Age = ");
    scanf("%d",&student2.age);
    printf("Dept = ");
    getchar();
    gets(student2.dept);




    printf("Name = ");
    puts(student2.name);
    printf("Age  = %d\n",student2.age);
    printf("Dept = ");
    puts(student2.dept);

}

Structure basic input output system (Structural data type example)

#include<stdio.h>

struct anything ///44 B
{
    int age;    ///4 B
    char name[20]; ///20 B           ///member definition
    char dept[10];///20 B

};
struct anything student1,student2 ;

Structure declaration and input output

#include<stdio.h>

struct anything ///44 B
{
    int age;    ///4 B
    char name[10]; ///20 B           ///member definition
    char dept[10];///20 B

};
struct anything student1 ;


Monday, March 27, 2017

Write a program that will take a string and count ' a '


#include<stdio.h>
#include<string.h>
main()
{
    int i,j,count=0;
    char str1[100],str2[100];
    printf("Enter first string   ");

write a program that will take 2 string from user and concatenate the 2nd string after first string

#include<stdio.h>
#include<string.h>
main()
{
    int i,j;
    char str1[100],str2[100];
    printf("Enter first string   ");
    gets(str1);/// str1 = "We"

write a program that will take 2 string from user and copy the string into first string

#include<stdio.h>
main()
{
    int i;
    char str1[100],str2[100];
    printf("Enter first string   ");
    gets(str1);/// str1 = "We"

write a program that will show the max value in an array using function

#include<stdio.h>
void maximum(int array[],int i)
{

    int max = array[0];///3

    int min = array[0];///3

Sunday, March 26, 2017

Array input and out and sum using function in c



///Array display using function

///write a program that will print their value and sum
#include<stdio.h>
int arrayDisplay(int b[],int i)
{
    int sum =0;
    for(i=0;i<5;i++)
    {
        printf("%d ",b[i]);
        sum =sum + b[i];

    }
   // printf("\nsum = %d\n",sum);
   return sum ;
}
void main()
{
    int a[]={3,4,5,6,7},i;
    printf("sum =%d",arrayDisplay(a,i));
}


Function in c with return example

/// write a program that will take two
///integers and find out their summation
///in add() function and also the subtraction in sub() function

#include<stdio.h>

int add(int a, int b )
{
    return a + b  ;

}

int sub(int a,int b)
{
    return a-b;

}


void main()
{
   scanf("%d%d",&a,&b);
   printf("Summation = %d \n",add(a,b));
   printf("subtraction = %d \n",sub(a,b));

}






Add sub and multiplication example in c with function 3

#include<stdio.h>

void add(int x ,int b,char letter)
{

    printf("summation=%d \n",x+b);

}

void sub(int x,int y)
{
    printf("subtraction=%d \n",x-y);

}

multi(int p,int q,float r)
{


    printf("multiplication=%f \n",p*q*r);

}

void main()
{

    printf("We R in main function \n");
    int a,b;
    printf("Enter 2 value \n");
    scanf("%d%d",&a,&b);
    add(a,b,'A'); ///parameter = pass by value
    sub(a,b);
    multi(a,b,8.5);


}






Add sub and multiplication in c with function 2

#include<stdio.h>
int a,b;
void add()
{
    //int a=6,b=3; // local var
//    a=6;
//    b=1;
    printf("Enter two values for addition \n");
    scanf("%d%d",&a,&b);
    printf("summation=%d \n",a+b);

}

void sub()
{
    printf("Enter two values for subtraction \n");
    scanf("%d%d",&a,&b);
    printf("subtraction=%d \n",a-b);

}

void multi()
{
    printf("Enter two values for multiplication \n");
    scanf("%d%d",&a,&b);

    printf("multiplication=%d \n",a*b);

}

main()
{


    printf("We R in main function \n");
    add();
    sub();
    multi();





}

Add sub and multiplication in c with function 1

#include<stdio.h>

void add()
{
    int a=6,b=3;
    printf("summation=%d \n",a+b);

}

void sub()
{
    int a=10,b=3;
    printf("subtraction=%d \n",a-b);

}

void multi()
{
    int a=10,b=3;
    printf("multiplication=%d \n",a*b);

}

main()
{


    printf("We R in main function \n");
    add();
    sub();
    multi();





}

Function example 1 in c

#include<stdio.h>
void shukrabad()
{
    printf("We R in Shukrabad\n ");
}
main()
{
    shukrabad();
    printf("We R in main function \n");
    shukrabad();

}

Thursday, March 23, 2017

String reverse in briefly


#include<stdio.h>
main()
{
    int i;
    char st[15];
    gets(st);///st="we are"
//    puts(st);///st="we"

//    for(i=0;i<st[i]!=NULL;i++)
//   {
//       //printf("%c",st[i]);
//       count++;
//   }
//   printf("Length=%d",count);
   //int length=strlen(st);
   //printf("Length=%d",length);
   for(i=strlen(st)-1;i>=0;i--)
   {
       printf("%c",st[i]);

   }
}

String reverse using strrev()

#include<stdio.h>

main()

{

    char st[15];

    gets(st);///st="we"

    puts(st);///st="we"

    strrev(st);///st="ew"

    puts(st);///st="ew"


}


Monday, March 20, 2017

Sum of 2 matrix

#include<stdio.h>
main()
{
    int row,col;
   int A[2][2]={3,4,2,6};
   printf("Matrix A :\n");

Input a matrix and output(2D Array practice)

#include<stdio.h>
main()
{
    int row,col,i,j;
     printf("Row number = ");
     scanf("%d",&row);///row = 3
     printf("Col number = ");
     scanf("%d",&col);///col = 2
     int A[row][col];

Declaration and print of 2 D Array

#include<stdio.h>
main()
{
    int row,col;
   int A[2][2]={3,4,2,6};
   printf("Matrix A :\n");
   for(row=0;row<2;row++)
   {
       for(col=0;col<2;col++)
       {
           printf("\tA[%d][%d]=%d ",row,col,A[row][col]);
       }
       printf("\n\n");
   }
   ///B mat
    int B[2][3]={3,2,6,4,7,8};
   printf("Matrix B :\n");
   for(row=0;row<2;row++)
   {
       for(col=0;col<3;col++)
       {
           printf("\t%d ",A[row][col]);
       }
       printf("\n");
   }
}