Wednesday, 4 April 2018

Pattern



    5
   54
  543
 5432
54321


int main()
{
  int i,j;
  for(i=5;i>=1;i--)
  {
    for(j=1;j<i;j++)
      printf(" ");
    for(j=5;j>=i;j--)
      printf("%d",j);
    printf("\n");
  }
  return 0;
}




     A
    ABA
   ABCBA
  ABCDCBA
 ABCDEDCBA
 
  1. #include<stdio.h>    
  2. int main(){  
  3.   int ch=65;    
  4.     int i,j,k,m;    
  5.   system("cls");  
  6.     for(i=1;i<=5;i++)    
  7.     {    
  8.         for(j=5;j>=i;j--)    
  9.             printf(" ");    
  10.         for(k=1;k<=i;k++)    
  11.             printf("%c",ch++);    
  12.             ch--;    
  13.         for(m=1;m<i;m++)    
  14.             printf("%c",--ch);    
  15.         printf("\n");    
  16.         ch=65;    
  17.     }    
  18. return 0;  
  19. }  


























Tuesday, 3 April 2018

Store Information of Student using File


Store Information of Student using File
############################################

#include <stdio.h>
int main()
{
   char name[50];
   int marks, i, num;

   printf("Enter number of students: ");
   scanf("%d", &num);

   FILE *fptr;
   fptr = (fopen("C:\\student.txt", "w"));
   if(fptr == NULL)
   {
       printf("Error!");
        }

   for(i = 0; i < num; ++i)
   {
      printf("For student%d\nEnter name: ", i+1);
      scanf("%s", name);

      printf("Enter marks: ");
      scanf("%d", &marks);

      fprintf(fptr,"\nName: %s \nMarks=%d \n", name, marks);
   }

   fclose(fptr);
  
}

Monday, 2 April 2018

Structure Program




Write a C program by using structure to display the information of Employee. It includes
name of the employee, age, salary and date of joining

===========================================


#include<stdio.h>
#include<string.h>
struct employee
{
char name[50];
int age;
int sal;
int joining;
}record;
int main()
{
record.age=14;
strcpy(record.name,"ram");
record.sal=1000;
record.joining=32;
printf("%s \n",record.name);
printf("%d \n",record.age);
printf("%d \n",record.sal);
printf("%d \n",record.joining);
return 0;
}



C program to add two integers using pointers.


#########  C program to add two integers using pointers.


#include <stdio.h>
int main()
{
   int first, second, *p, *q, sum;

   printf("Enter two integers to add\n");
   scanf("%d%d", &first, &second);

   p = &first;
   q = &second;

   sum = *p + *q;

   printf("Sum of the numbers = %d\n", sum);

   return 0;
}



Tuesday, 27 March 2018

Palindrome of String

##############Palindrome of String ##############


#include <stdio.h>
#include <string.h>

int main(){
    char string1[20];
    int i, length;
    int flag = 0;
   
    printf("Enter a string:");
    scanf("%s", string1);
   
    length = strlen(string1);
   
    for(i=0;i < length ;i++){
        if(string1[i] != string1[length-i-1]){
            flag = 1;
            break;
   }
}
   
    if (flag) {
        printf("%s is not a palindrome", string1);
    }   
    else {
        printf("%s is a palindrome", string1);
    }
    return 0;
}

Monday, 26 March 2018

Sum of Diagonal of matrix




    #include <stdio.h>

    void main ()

    {

         static int array[10][10];

        int i, j, m, n, a = 0, sum = 0;


        printf("Enetr the order of the matix \n");

        scanf("%d %d", &m, &n);

         if (m == n )

        {

             printf("Enter the co-efficients of the matrix\n");

            for (i = 0; i < m; ++i)

            {

                for (j = 0; j < n; ++j)

                {

                    scanf("%d", &array[i][j]);

                }

            }

            printf("The given matrix is \n");

            for (i = 0; i < m; ++i)

            {

                for (j = 0; j < n; ++j)

                {

                    printf(" %d", array[i][j]);

                }

                printf("\n");

            }

             for (i = 0; i < m; ++i)

            {

                sum = sum + array[i][i];

                a = a + array[i][m - i - 1];

            }

            printf("\nThe sum of the main diagonal elements is = %d\n", sum);

            printf("The sum of the off diagonal elements is   = %d\n", a);

         }

         else

            printf("The given order is not square matrix\n");

     }

Transpose Of Matrix




#include <stdio.h>

int main()
{
    int a[10][10], transpose[10][10], r, c, i, j;
    printf("Enter rows and columns of matrix: ");
    scanf("%d %d", &r, &c);

    // Storing elements of the matrix
    printf("\nEnter elements of matrix:\n");
    for(i=0; i<r; ++i)
        for(j=0; j<c; ++j)
        {
            printf("Enter element a%d%d: ",i+1, j+1);
            scanf("%d", &a[i][j]);
        }

    // Displaying the matrix a[][] */
    printf("\nEntered Matrix: \n");
    for(i=0; i<r; ++i)
        for(j=0; j<c; ++j)
        {
            printf("%d  ", a[i][j]);
            if (j == c-1)
                printf("\n\n");
        }

    // Finding the transpose of matrix a
    for(i=0; i<r; ++i)
        for(j=0; j<c; ++j)
        {
            transpose[j][i] = a[i][j];
        }

    // Displaying the transpose of matrix a
    printf("\nTranspose of Matrix:\n");
    for(i=0; i<c; ++i)
        for(j=0; j<r; ++j)
        {
            printf("%d  ",transpose[i][j]);
            if(j==r-1)
                printf("\n\n");
        }

    return 0;
}