• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » C » C Programming

C Program Print Link List

By Dinesh Thakur

 

#include<stdio.h> 
#include<process.h>
struct list
{
     int info;
     struct list *link;
};
        struct list start,*temp,*prev,*node;
        void insert()
      {
              int i,j,item;
              printf("Enter the item to insert=");
              scanf("%d",&item);
              printf("\n 1.insertion at begining");
              printf("\n 2.insertion at end");
              printf("\n 3.insertion at middle");
              printf("Enter your choice=");
              scanf("%d",&i);
              switch(i)
                 {
                           case 1:if(start.link==NULL)
                                       {
                                                     node=(struct list *)malloc(sizeof(struct list));
                                                     node->info=item;
                                                     node->link=NULL;
                                                     start.link=node;
                                                     return;
                                        }
                                      else
                                       {
                                                     node=(struct list *)malloc(sizeof(struct list));
                                                     node->info=item;
                                                     node->link=start.link;
                                                     start.link=node;
                                                     return;
                                        }
                            case 2:if(start.link==NULL)
                                       {
                                                     node=(struct list *)malloc(sizeof(struct list));
                                                     node->info=item;
                                                     node->link=NULL;
                                                     start.link=node;
                                                     return;
                                        }                      
                                       else
                                       {
                                                     temp=start.link;
                                                     while(temp->link!=NULL)
                                                            {
                                                                     temp=temp->link;
                                                            }
                                                                     node=(struct list *)malloc(sizeof(struct list));
                                                                     temp->link=node;
                                                                     return;
                                        }
                             case 3:printf("Enter position=");
                                                    scanf("%d",&j);
                                                    if(start.link==NULL)
                                                      {
                                                               node=(struct list *)malloc(sizeof(struct list));
                                                               node->info=item;
                                                               node->link=NULL;
                                                               start.link=node;
                                                               return;
                                                       }
                                                      else
                                                       {
                                                               temp=start.link;
                                                               while(temp->link!=NULL)
                                                                      {
                                                                             if(temp->info==j)
                                                                               {
                                                                                     break;
                                                                                }
                                                                                     temp=temp->link;
                                                                       }
                                                                                     node=(struct list*)malloc(sizeof(struct list));
                                                                                     temp->link=node;
                                                                                     return;
                                                        }
                                                                                     default:printf("Wrong choice");
                  }
       }
        int del()
     {
          int i,j,item;
          printf("/n1.Deletion at beginning");
          printf("/n2.Deletion at end");
          printf("/n3.Deletion at middle");
          printf("Enter the choice");
          scanf("%d",&i);
          switch(i)
          {
            case 1:if(start.link==NULL)
                   {
                           printf("list empty");
                           return 0;
                   }
                   else
                   {
                           temp=start.link;
                           item=temp->info;
                           start.link=temp->link;
                           free(temp);
                           return item;
                   }
            case 2:if(start.link==NULL)
                   {
                           printf("list empty");
                           return 0;
                   }
                   else
                   {
                           temp=start.link;
                           prev=&start;
                           while(temp->link!=NULL)
                                  {
                                        temp=temp->link;
                                        prev=prev->link;
                                  }
                                        item=temp->info;
                                        prev->link=NULL;
                                        free(temp);
                                        return item;
                   }
            case 3:if(start.link==NULL)
                   {
                         printf("list empty");
                         return 0;
                    }
                   else
                  {
                        printf("enter the item to be deleted");
                        scanf("%d",&i);
                        temp=start.link;
                        prev=&start;
                        while(temp->link!=NULL)
                               {
                                      if(temp->info==i)
                                    {
                                         break;
                                    }
                                         prev=prev->link;
                                         temp=temp->link;
                                }
                           if(temp->link==NULL)
                            {
                                  printf("item not available");
                                  return 0;
                             }
                            else
                            {
                                  item=temp->info;
                                  prev->link=temp->link;
                                  free(temp);
                                  return item;
                             }
                     }
                                  default:printf("wrong choice");
           }
       }
                 void display()
              {
                        temp=start.link;
                        while(temp)
                               {
                                       printf("%d",temp->info);
                                       temp=temp->link;
                               }
              }
void main()
       {
            void insert();
            int del();
            void display();
            int i,j,k;
           char ch;
           clrscr();
           start.link=NULL;
           do
            {
                clrscr();
                printf("\n1.Insert");
                printf("\n2.Delete");
                printf("\n3.Display");
                printf("\n4.Exit");
                printf("\nEnter your Choice :");
                scanf("%d",&i);
                switch(i)
                    {
                          case 1:insert();
                                                 display();
                                                 break;
                          case 2:j=del();
                                                 printf("item deleted is %d\n",j);
                                                 display();
                                                 break;
                          case 3:display();
                                                 break;
                          case 4:exit(0);
                                                default:printf("wrong choice");
                    }
                                                fflush(stdin);
                                                printf("any more?=");
                                                scanf("%c",&ch);
            }while(ch=='y');
              getch();
       } 

C Program Print HCF of N Numbers

By Dinesh Thakur

 

#include<stdio.h> 
void main()
{
    int i,j,h,n,a[100];
    int hcf(int,int);
    clrscr();
    printf("Enter how many numbers :");
    scanf("%d",& n);
    for(i=0;i<n;i++)
        {
            printf("Enter a Number :");
            scanf("%d",& a[i]);
        }
            for(i=0;i<n-1;i++)
                {
                     h=hcf(a[i],a[i+1]);
                     a[i+1]=h;
                }
                     printf("The HCF is :  %d",h);
                     getch();
  }
       int hcf(int a,int b)
         {
              if(a%b==0)
               {
                      return b;
               }
              else
              {
                      return(hcf(b,a%b));
              }
         } 

Print HCF of N Numbers

C Program Print First N Prime Number using Recursion

By Dinesh Thakur

 In this program required variable are declared for functioning criteria. Then using loop statement for fulfilling the requirement of repeat the process. Then to use if condition to check whether the number is prime or not. After finding the prime number the next process is to elaborate them using while statement or if condition if number division able by declare value then break the statement else it will increase the value for variable and then if (y==x) then return the value as required.

Problem statement:-
This program is an implementation about to print first N prime number using recursion function.

  1. Declaring Variable as required.
  2. Using required function or statements.
  3. Display result on the screen.

This C program is successfully compiled and run on a System. Output is shown below.

void main()
{
         int a[100],i,j,k,n,b;
         int prime(int);
         clrscr();
         printf("Enter no of elements : ");
         scanf("%d",&n);
         printf("Enter a no : ");
         for(i=0;i<n;i++)
             {                
                 scanf("%d",&a[i]);
             }
                for(i=0;i<n;i++)
                    {
                        b=prime(a[i]);
                        if(b==a[i])
                         {
                              printf("Prime Number is : %d\n",a[i]);
                         }
                   }
                             getch();
}
            int prime(int x)
       {
             int y=2;
             while(y<100)
                   {
                       if(x%y==0)
                         {
                             break;
                         }
                      else
                        {
                             y=y++;
                        }
                  }
                      if(y==x)
                       {
                              return x;
                       }
      }

First N Prime Number using Recursion

C Program Write a Program to Print a Pascal Triangle

By Dinesh Thakur

In this program to Print the Pascal Triangle Two core concepts will be on the trot. The Control statement (if-else), and Loop Statements. There in the program Integer type Variables declare which use to contain the value. Here variable i,j and Num will use in the Loop statement as according the requirement. As required in the program Nested Loop used for fulfilling the condition along within the control Statement.

In the Program to print Triangle the loop Statement will be used many times like nested Loop Statement. As shown in The Program value entered in condition place and with the if condition used either condition gets true will be print desired row or else part will be followed to print in else condition the calculation will be manipulated for getting the correct output.
Problem Statement:-
Pascal Triangle Which we might have studied in Binomial Theorem here we Print Pascal Triangle. With the use of Loop Statement and Control statement. Write a program to read the data and determine the following:

  1. Entering the Number for Triangle.
  2. Using loop Statement.
  3. Using Control Statement for condition.
  4. Display output on the Screen.

This C program is successfully compiled and run on a System. Output is shown below.

#include<stdio.h>
#include<conio.h>
void main()
{
            int i=1,j,num,x=1;
            clrscr();
            printf("Please Enter the Number :");
            scanf("%d",&num);
            printf("\n\n");
            printf("OUTPUT:\n");
            printf("------");
            printf("\n\n");
            printf("The Pascal Triangle is \n");
            printf("**********************\n");
            for(i=1;i<=num;i++)
                 {
                    for(j=1;j<=i;j++)
                        {
                            if(j==1)
                              {
                                     x=1;
                                     printf("%d",x);
                               }
                            else
                              {
                                     x=(x*(i-j+1)/(j-1));
                                     printf("%d",x);
                               }
                       }
                                     printf("\n");
                }
                                     getch();
}
 

Print a Pascal Triangle

 

C Program Pass Array to Function

By Dinesh Thakur

In this program user ask to pass array to function. User declare the variables along with functions for process to pass array like void read (), void dis (). Arguments also declared within function to pass value. Array type variable contains the array elements within. User asks to enter the value as regarding. And then user call the function for passing value to array in a function user declares for loop for to print a value. The other function is been also call and loop statement also declare for another printing method. And display on the screen.

Problem statement:
This is C program that asks user to show how to pass a value on the array through function.

  1. Declaring the variables.
  2. Using functions.
  3. Using loop statements.
  4. Display result on the screen.

Here is C source code for passing array to function. Output of this program shown below. 

#include<stdio.h>
#include<conio.h>
void read(int *,int);
void dis(int *,int);
void main()
   {
         int a[5],b[5],c[5],i;
         clrscr();
         printf("Enter the Elements of First List :");
         read(a,5);
         printf("The Elements of First List are : ");
         dis(a,5);
         getch();
   }
         void read(int c[],int i)
      {
            int j;
           for(j=0;j<i;j++)
               scanf("%d",&c[j]);
               fflush(stdin);
      }
         void dis(int d[],int i)
     {
            int j;
            for(j=0;j<i;j++)
                 printf("%d ",d[j]);
                 printf("\n");
     } 

Pass Array to Function

C Program Write a Program to ForEach

By Dinesh Thakur

 

 

#include<stdio.h> 
main()
{
  int a[5],i,num;
  clrscr();
  for(i=0;i<=4;i++)
    {
      printf("enter the values of 1st matrix=");
      scanf("%d",&a[i]);
    }
    printf("enter the value you want to search");
    scanf("%d",&num);
      for(i=0;i<=4;i++)
         {
            if(num==a[i])
              {
                 printf("number is present=%d",num);
                 break;
              }
         }
         if(i>4)
         printf("number is not present");
 getch();
}
 

C Program Find Transpose of a Matrix

By Dinesh Thakur

This is a C program where user asks to enter the value of matrix (order of matrix) and to find the transpose of matrix order. Means the rows will convert through columns what else the order of matrix. 

In the program variables are declared of Array type that will contain the value. User ask to enter value and the loop statement for verify the condition. The early loop statement will use to print a Matrix and the next one for finding the transpose of matrix. Nested loop statement is implemented in this program. And in the end to print the value on the screen.
Problem Statement:
This is C program to find the Transpose of matrix. User has to print a Matrix for transpose process.

  1. Declaring variable.
  2. Using loop statement.
  3. Printing result on the screen.

Here is source code of the C program to find the transpose of the matrix. The C program is successfully compiled. The program output is also shown below.

#include <stdio.h> 
void main ( )
{
    int a[3][3],b[3][3],i,j,k;
    clrscr();
    printf("Enter Element for 3 x 3 Matrix\n");
    printf("Enter no. : ");
    for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
                {    
                   scanf("%d",&a[i][j]);
                }
        }
           printf("\n");
           for(i=0;i<3;i++)
               {
                 for(j=0;j<3;j++)
                     {
                        printf("%d",a[i][j]);
                        printf(" ");
                     }
                        printf("\n");
               }
                        for(i=0;i<3;i++)
                            {
                                 for(j=0;j<3;j++)
                                    {
                                        b[i][j]=a[j][i];
                                    }
                             }
                                  printf("\nThe Transpose is :\n");
                                  printf("\n");
                                  for(i=0;i<3;i++)
                                      {
                                          for(j=0;j<3;j++)
                                               {
                                                   printf("%d",b[i][j]);
                                                   printf(" ");
                                               }
                                                   printf("\n");
                                      }
                                                   getch();
}

Transpose of a Matrix

C Program Write a Program to Find the Greatest Between 3 Number

By Dinesh Thakur

Let us use variables a, b and c (all of type int) to represent three integer numbers and variable max (also of type int) to represent the maximum of them.

It first accepts the values of variables a, b and c. To determine the maximum number, the larger number of a and b is first assigned to max using the if-else statement. Then the larger of variables max and c, which is the maximum of the three given numbers, is determined using a simple if statement. Finally, the value of max is printed. The program is given below.  

void main()
{
       int a,b,c;
       clrscr();
       printf("Enter the Value of a = ");
       scanf("%d",&a);
       printf("Enter the Value of b = ");
       scanf("%d",&b);
       printf("Enter the Value of c = ");
       scanf("%d",&c);
       if (a>b&&a>c)
         {
                 printf("a is Greater ");
         }
      else if(b>a&&b>c)
              {
                   printf("b is Greater");
              }
      else
             {
                   printf("c is Greater");
             }
                   getch();
}

C Program to Find the Greatest Between 3 Number

C Program Write a Program to Find the COS Theta Value

By Dinesh Thakur

This program asks user to find out the cos (Cosine) theta value. Cosine is a trigonometric element that uses in the math function. User defines the PI value for functions user also declares the variables for the required condition. User ask to enter the value for the X. then it’s manipulated by PI and trespass the value to cosz=term and further passes to loop statement for printing out the output for cosine value on to the display.

Problem Statement:

This is C program that asks user to find out the cosine value.

  1. Declare the variables.
  2. Using loop statement.
  3. Display result on the screen.

Here is C source code for finding out the Cosine value. Output of this program shown below. 

#include<stdio.h> 
#include<conio.h>
#include<math.h>
#define ACC 0.0001
#define PI 3.14
void main()
{
         int x,i;
         float x1,x2,cosz=0,term;
         clrscr();
         printf("Enter the X value:");
         scanf("%d",&x);
         x1=(x*PI)/180;
         // printf("%f",cos(x1));
        x2=x1*x1;
        term=1;
        cosz=term;
        for(i=2;fabs(term)>ACC;i=i+2)
            {
                 term = (x2*(-term))/(i*(i-1));
                 cosz = cosz+term;
            }
                 printf("\nNew Value : %f",cosz);
                 getch();
}
Output :

C Program Write a Program to Enter Char and Check its ASCII Code or Not

By Dinesh Thakur

This program asks user to check whether the given char code is ASCII or not. ASCII code means the character code that brings in a numeric form for every character so that computer can read the content because computer only understands the machine language or binary system. ASCII stands for (American standard code for information interchange). There are different type of ASCII code like for Capital characters ASCII code numeric value starts from 65 (A=65) or small characters like a starts from 97 (a=97).

In this program user need to check out the ASCII code for character for this user declare a variable name m1 that will be contain the value for ASCII code checking process. User uses control statement for checking the ASCII code. User asks to enter the value as character. if(m1>=65&&m1<=90) then the character value will be added with 32 to find out the ASCII value else the condition will be if(m1>=97&&m1<=122) then the value will be deducted from 32. And if not any condition lies true then message will be nothing for both character values.
Problem Statement:
This is C program to check out the ASCII code value for character.

  1. Declare the variables.
  2. Using control statements.
  3. Display result on the screen.

Here is C source code for Checking out the ASCII value for character. Output of this program shown below. 

#include<stdio.h> 
void main()
{
      char m1,m2;
      clrscr();
      printf("Enter any Char : ");
      scanf("%c",&m1);
      if(m1>=65&&m1<=90)
        {
           m2=m1+32;
           printf("m2 : %c",m2);
        }
     else if(m1>=97&&m1<=122)
       {
                  m2=m1-32;
                  printf("m2 : %c",m2);
       }
     else
                  printf("Nothing");
                  getch();
}

Char and Check its ASCII Code or Not

Write a Program to Create a Structure of N Students using Dynamic Memory Allocation. Read their Names & Print the Result

By Dinesh Thakur

 A structureincludes manyvariablesinto one.Works asa Report cardthat hasname, marks and total.Therecordwould bea structure.The structurethenis used to groupa set ofsimilar datanotforming anew data type.

Tocreate a structurewe use thestructcommand.Its general formis:

struct student
{
    char name[10];
    int m[3];
    int total;
    char result[5];
}p,s;

Thestudent is the name forthe structure. Thep and sare optional andwould bevariable namesthatyou‘d be declaring andthat would be ofstudent type.A first example:

# include <string.h>
# include <stdio.h>
struct student
{
        char name[10];
        int m[3];
        int total;
        char result[5];
}*p,*s;
        void main()
    {
              int i,j,l,n;
              clrscr();
              printf("Enter the no. of students : ");
              scanf("%d",&n);
              p=(struct student*)malloc(n*sizeof(struct student));
              s=p;
              for(i=0;i<n;i++)
                  {
                             printf("Enter a name : ");
                             scanf("%s",&p->name);
                             p-> total=0;l=0;
                             for(j=0;j<3;j++)
                                {
                                     one:printf("Enter Marks of %d Subject : ",j+1);
                                     scanf("%d",&p->m[j]);
                                     if((p->m[j])>100)
                                        {
                                            printf("Wrong Value Entered");
                                            goto one;
                                        }
                                            p->total+=p->m[j];
                                            if(p->m[j]<40)
                                                l=1;
                                  }
                                            if(l==0)
                                              strcpy(p->result,"PASS");
                                            else
                                              strcpy(p->result,"FAIL");
                                              p++;
                      }
                                              for(i=0;i<n;i++)
                                                  {
                                                        printf("\n%s\t%s",s->name,s->result);
                                                        s++;
                                                  }
                                                        getch();
       } 

Structure of N Students using Dynamic Memory Allocation

C Program Write a Program to Check the Number Odd or Even

By Dinesh Thakur

This is program that ask user to check whether the given number is odd or even. That number divided by odd number Is odd else it is even. In this program user declare required variables that are use to contain the value. And the control statement also used like if else for checking the manipulated condition. If the given digit division able with odd number then it will be odd else it will be even number.

Problem Statement:
This is the C program where users ask to check the number is odd or even.

  1. Declaring variable.
  2. Using control statement.
  3. Display result on the screen.

Here is C source code for check whether the Given Number is odd or even. The output of this program shown below

[Read more…] about C Program Write a Program to Check the Number Odd or Even

C Program Write a Program to Check the Number Divisible by 5 or Not

By Dinesh Thakur

In this program user checks the logic about numeric value that will it be Division able with 5 or not. To check this declares a variable of integer type. And a logic will be used along with the Modulus operator(%).that will be manipulate with the numeric value and control statement (if-else) used if the numeric value is dividable than output will be ok else it will be reverse. 

Problem Statement:
This is the program to check whether the Numeric value is division able with 5 or Not.

  1. Enter Numeric value.
  2. Use Logic to manipulate.
  3. Declare if-else Condition.
  4. Displaying output on the Display.

Here is source code of the C program to Check out The Numeric value is Division able with 5 or Not. The C program is successfully compiled. The program output is also shown below.

#include<stdio.h>
void main()
{
         int a;
         clrscr();
         printf ("Enter the no.");
         scanf("%d",&a);
         if(a%5==0)
          {
             printf("No.is Divisible by 5");
          }
         else
         {
               printf("No is not Divisible by 5");
         }
               getch();
}

Check the Number Divisible by 5 or Not

C Program Write a Program to Check the Day in Week

By Dinesh Thakur

This is C program that ask user to check the day in week that is been selected. For this user need to declare the variables for this and the user also uses the switch statement for choice base condition to chose the day in a week. As user declare simple switch statement each case statement for every day after declaring the case statement user ask to put a number the number will be from 1-7 otherwise it will be an invalid number. default case shows the message invalid number if the number out of case that user select.

Problem statement:
This is C Program that asks user to find out the days in a week.

  1. Declare variables.
  2. Using switch statement.
  3. Display result on the screen.

Here is C source code for check the day in a week. Output of this program shown below. 

#include<stdio.h> 
#include<conio.h>
void main()
{
       int a;
       clrscr();
       printf("Enter a no. :");
       scanf("%d",&a);
       switch(a)
         {                                       
                 case 1:printf("Monday");break;
                 case 2:printf("Tuesday");break;
                 case 3:printf("Wednesday");break;
                 case 4:printf("Thrusday");break;
                 case 5:printf("Friday");break;
                 case 6:printf("Saturday");break;
                 case 7:printf("Sunday");break;
                 default : printf("Invalid no.");
          }
                 getch();
}
Output:

Check the Day in Week

C Program Write a Program to Check the Char is Vowel or Not

By Dinesh Thakur

A given character is a vowel if it is one of the following characters: A, E, I, O and U. The switch case given below tests whether a given character is a vowel or not.

Note that we have to compare variable ch with uppercase as well as lowercase letters. We can reduce the number of comparisons in the above code if we first convert the given character to uppercase (or lowercase) representation. Thus, the condition in the switch involves comparison with uppercase (or lowercase) letters only. The code using this approach is given below.

#include<stdio.h> 
void main()
{
         char a;
         clrscr();
         printf("Enter any Alphabet : ");
         scanf("%ch",&a);
         switch (a)
              {
                  case'A':
                  case'a':
                  case'E':
                  case'e':
                  case'I':
                  case'i':
                  case'O':
                  case'o':
                  case'U':
                  case'u':
                                 printf("It is a Vowel");
                                 break;
                  default:
                                 printf("It is a Consonent");
}
                                 getch();
}
Output :
Enter any Alphabet : i
It is a Vowel

C Program Calculate Sum of Upper and Lower Triangle of a Matrix

By Dinesh Thakur

In this program user ask to make sum of upper and lower triangle of matrix. In this program user declare the array type Variable after declaring value to the variable if statement will be use to check whether the matrix is square or not. Else it will be going to enter elements for matrix. Loop statement will use to calculate the procedure for elements. For loop and control statements will use the procedure to make it. Then a print method will use to display the sum of upper triangle.

Next move is to calculate the sum of lower matrix triangle as per procedure. Here the same logic use to calculate the sum of lower matrix triangle along with using loop statement and control statement and to get the result in the end.
Problem Statement:-
This program is an implementation about to calculate the sum of lower and upper triangle matrix.

  1. Enter the matrix elements.
  2. Checks the mode of matrix.
  3. Display the result on screen.

This C program is successfully compiled and run on a System. Output is shown below. 

#include<stdio.h>
void main()
{
     int a[10][10],sum=0,sm=0;
     int i,j,m,n;
     clrscr();
     printf("Enter Order of Matrix : ");
     scanf("%d%d",&m,&n);
     if(m!=n)
       {
           printf("Not a Square Matrix : ");
           getch();
           exit();
       }
           printf("Enter Elements : ");
           for(i=0;i<m;i++)
               {
                  for(j=0;j<n;j++)
                      {
                          scanf("%d",&a[i][j]);
                      }
               }
                  for(i=0;i<m;i++)
                      {
                          for(j=0;j<n;j++)
                              {
                                  if(i+j<m-1)
                                    {
                                         sum+=a[i][j];
                                    }
                               }
                      }
                          printf("\n Sum of Upper Triangle is : %d",sum);
                          for(i=0;i<m;i++)
                              {
                                  for(j=0;j<n;j++)
                                      {
                                         if(i+j>m-1)
                                           {
                                                sm+=a[i][j];
                                            }
                                       }
                              }
                                   printf("\n Sum of Lower Triangle is : %d",sm);
                                   getch();
} 

Sum of Upper and Lower Triangle of a Matrix

C Program Calculate Sum of Diagonal Elements of a Matrix

By Dinesh Thakur

In this program, two variables of array type element declared. Which contains the value of declared variables and Loop statement will also use to be execute the situation. The loop statement will elaborate its functioning until the condition get false. The other function is to be comparing if (m! = n) that will end the functioning of add the Matrix given components must be define all the conditions true. And the result as output also displayed on the screen as well.

Problem Statement:
In this calculation the two diagonal elements will be added for perception of output. Write a program to read the data and determine the following:

  1. Declaring required Variables.
  2. Entering the Order of Matrix element.
  3. Defy The Loop statement with required condition.
  4. Displaying the Output on the Screen.

The Source Code is written below. This Program is well Compiled and runs well as required.

#include<stdio.h>
  void main()
  {
   int a[10][10],sum=0;
   int i,j,m,n;
   clrscr();
   printf("Enter Order of Matrix = ");
   scanf("%d%d",&m,&n);
   if(m!=n)
     {
          printf("Not a Square Matrix : ");
          getch();
          exit();
     }
          printf("Enter Elements : ");
          for(i=0;i<m;i++)
              {
                  for(j=0;j<n;j++)
                      {
                         scanf("%d",&a[i][j]);
                      }
               }
                  for(i=0;i<m;i++)
                      {
                          for(j=0;j<n;j++)
                              {
                                    if(i==j)
                                      {
                                          sum+=a[i][j];
                                       }
                               }
                       }
                   printf("Sum of Diagonal Elements = %d ",sum);
                   getch();
  }

Sum of Diagonal Elements of a Matrix

 

C Program Write a Program For Sine Series

By Dinesh Thakur

 In this program user ask to compute Sine (trigonometric function) Series. The Variable of float or integer type declared that will be use to contain the value. User asks to enter the value and then the computation of PI function described. Here term variable used for temporary value container as in the program this variable contain the x1 and then swapped for Sine. For loop statement also been used for varying the condition. Then using compatible condition the output is displayed.

Problem Statement:
The trigonometric Symbol Sine Series to be computed through a C program.

  1. Declare Value of PI and ACC.
  2. Used Computation algorithm.
  3. Using Loop Statement.
  4. Display result On the Screen.

Here is source code of the C program to compute the Sine Series. The C program is successfully compiled. The program output is also shown below.

#include<stdio.h> 
#include<conio.h>
#include<math.h>
#define ACC 0.000001
#define PI 3.14
void main()
{
          int x,i;
          float x1,x2,sine=0,term;
          clrscr();
          printf("Enter the X value : ");
          scanf("%d",&x);
          x1=(x*PI)/180;
          x2=x1*x1;
          term=x1;
          sine=term;
          for(i=3;fabs(term)>ACC;i=i+2)
              {
                    term = (x2*(-term))/(i*(i-1));
                    sine = sine+term;
              }
                    printf("\n%f",sine);
                    getch();
}
Output :
Enter the X value : 100
0.984961 

C Program For Replace a String

By Dinesh Thakur

In this program user asks to replace the string from existing one. User declares required char type variables that will be used to store the value. Here in operation mode user declare nested for loop statement in that statement user elaborate the variables that are used to functionality mode. Here in other type mode user also use if condition along within do while loop. If (l1>=l2) condition got true than do while loop will come in function. In do while condition for loop also exists for replacing the character and an if-else condition too. Condition going to be check that if the character exists in the string or not the condition got true then it will replace the character. And display the result on the screen.

Problem statement:
This is C Program that asks user to replace the character from the existing one.

  1. Declaring the variable.
  2. Using while condition.
  3. Using loop statement.
  4. Display the result on screen.

Here is C source code for replacing the character from string. The output of this program shown below. 

#include<stdio.h> 
#include<conio.h>
void main()
{
         char a[100],b[100],c[100],d[100];
         int i,j,k,l1,l2,l3,m,count=-1;
         clrscr();
         printf("\t\t\t   REPLACE OF STRING ");
         printf("\n\t\t\t********************");
         printf("\n\n\t INPUT");
         printf("\n\t*******");
         printf("\n\nEnter the First String : ");
         scanf("%[a-z ]s",a);
         printf("\nEnter the Substring : ");
         scanf("%s",b);
         printf("\nEnter the Replace String : ");
         scanf("%s",c);
         printf("\n\n\tOUTPUT");
         printf("\n\t*******");
         for(i=0;a[i]!='\0';i++)
              l1=i;
              for(i=0;b[i]!='\0';i++)
                   l2=i;
                   for(i=0;c[i]!='\0';i++)
                        l3=i;
                        for(i=0;a[i]!='\0';i++)
                             d[i]=a[i];
                             d[i]='\0';
                             if(l1>=l2)
                              {
                                 do
                                   {
                                       for(i=0,j=0;a[i]!='\0' && b[j]!='\0';i++ )
                                           {
                                                 if(a[i]==b[j])
                                                   {
                                                      count++;
                                                      j++;
                                                    }
                                                   else
                                                    {
                                                            count=-1;
                                                             if(j>0)
                                                                i--;
                                                                j=0;
                                                     }
                                              }
                                                                m=i;
                                                     if(count==l2)
                                                       {
                                                            i=i-j;
                                                            for(k=0;c[k]!='\0';i++,k++)
                                                                  a[i]=c[k];
                                                                  if(l2!=l3)
                                                                    {
                                                                        for( ;d[m]!='\0';m++,i++)
                                                                             {
                                                                                  a[i]=d[m];
                                                                              }
                                                                     }
                                                                                  //a[i]='\0';
                                                                                  //printf("\nReplaced string:%s",a);
                                                          }
                                                                                   else
                                                                                   break;
                                                                                   //printf("\nThe substring is not there");
                                     }while(a[i]!='\0');
                                       printf("\nReplaced string:%s",a);
                               }
                                       getch();
}

C Program Write a Magic Number Program

By Dinesh Thakur

 This is C Program Write a Magic Number Program. In this program user ask to guess whether the guessed number is correct or not. The casually in this program the Control Statement will be used like if-else. If the guessed number is equal to the number that set for variable then it’s right else it will be wrong the variable declared which use to contain the given value for condition checks out. After the condition got completed the result will be on the display.

Problem Statement:
This is the program to check out the magic number from guessing digit.

  1. Enter the digit for check.
  2. Execute the control statement.
  3. Display result on the screen

Here is source code of the C program to check out the magic number from guessing digit. The C program is successfully compiled. The program output is also shown below.

#include<stdio.h> 
void main()
{
       int magic =23;
       int guess;
       clrscr();
       printf("Enter your Guess for the Number : ");
       scanf("%d",& guess);
       if(guess==magic)
        {
            printf("\nCongratulation Right Guess");
        }
      else
       {
            printf("\nSorry Wrong Guess");
       }
            getch();
}
Output :
Enter your Guess for the Number : 23
Congratulation Right Guess

C Program Reverse the Entered Number

By Dinesh Thakur

In this program user ask to reverse the Entered number. User declares the required variables for storing the value. User asks to enter the number. User declares the loop statement for reversing the number. Here user also declares the swapping method for this convention like b=a%10, c=a/10, a=c. printing out the condition on display as result on the mark.

Problem Statement:

This is C program that asks user to reverse the entered Number.

  1. Declaring the variables.
  2. Using loop statement.
  3. Display result on the screen.

Here is C source code for reversing the 10 digit number. Output of this program shown below. 

#include<stdio.h>
#include<conio.h>
void main()
{
          long int a;
          int b,c,i;
          clrscr();
          printf("This will Reverse the Entered number : \n");
          printf("Please Enter the Five Digit Number : \t");
          scanf("%ld",&a);
          for(i=1;i<=5;i++)
              {
                     b=a%10;
                     c=a/10;
                     a=c;
                     printf("%d ",b);
              }
                     getch();
} 

Reverse the Entered Number

C Program Returns NonZero if CH is a LowerCase Letter; OtherWise Zero is Reture

By Dinesh Thakur

This is C program to check out the content is lower case or uppercase. Core concept is to show the if the content CH is lower case then Non Zero result will be display as result else the result will zero. For this user declare some required variables for containing the values. Then user define if statement along with for loop. The condition which gets the true will display as result on screen.

Problem Statement:
This is C program that ask user to check out the content is lower or uppercase.

  1. Declare the variables.
  2. Using the method.
  3. Display result on the screen.

Here is C source code to check out the content is lower or uppercase. The output of this program shown below.

#include <ctype.h> 
#include <stdio.h>
int main(void)
{
    char ch;
    clrscr();
      for(;;)
            {
                    ch = getchar();
                    if(ch == '.')
                     {
                             break;
                     }
                   if(islower(ch))
                     {
                           printf("%c is lowercase\n", ch);
                     }
            }
                           getch();
                           return 0;
}

C Program Returns NonZero if its Arg is either a Letter or a Digit returns zero

By Dinesh Thakur

 

#include <ctype.h> 
#include <stdio.h>
int main(void)
{
    char ch;
    clrscr();
    printf(". to exit:");
    for(;;)
        {
           ch = getc(stdin);
           if(ch == '.')
             break;
           if(isalnum(ch))
             printf("%c is alphanumeric\n", ch);
        }
             getch();
             return 0;
  } 

C Program Replace Character with an Equivalent Encoded Character

By Dinesh Thakur

 

#include <stdio.h> 
void main( )
{
    char line [80] ;
    int  count ; /* read i n the e n t i r e s t r i n g */
    printf ("Enter  a  line  of  text  below:\n");
    scanf ( "%s\ n",line ) ;
    for (count = 0; line[count] != '\0' ; ++count)
    {
            if (((line[count] >= '0')&& (line[count] < '9')) || ((line[count] >= 'A') && (line[count] <'Z' ) ) || ((line[count] >= 'a') && (line[count] < 'z')))
              putchar(line[count] + 1);
       else if (line[count] == '9' ) putchar('0');
       else if (line[count] == 'Z' ) putchar('A');
       else if (line[count] == 'z' ) putchar('a');
       else putchar('.');
    }
} 

C Program Print The Number

By Dinesh Thakur

This is c program that asks user to print the number on screen. User declares some variables that use to contain the value in it. User also uses the switch statement for this execution. User ask to enter the number and in switch statement user declare for loop i=2 and <20 any number been entered the increment operator will increase i+1. Case 2 has the same condition increment operator will increase the number i+2. And default case will show the message “enter valid number“. Display the result on the screen as output.

Problem Statement:
This is C program that ask user to print the number on screen.

  1. Declare the variable.
  2. Using switch statement along with for loop.
  3. Display the result on screen.

Here is C source code to print the number on screen. Output of this program shown below. 

[Read more…] about C Program Print The Number

C Program How to Pass Two Dimensional Array to a Function in C

By Dinesh Thakur

In this program user ask to convey that how to pass 2d array to a function. User define value in first instance for M=3, N=5. User also declare array type variable for storing the value. User input a message that prints a matrix for and then returns a value. Next move two functions are made for passing array like fstore, fretrieve and the loop statement also declares in the function for varying the condition. Nested loop statement is been implemented for the function. And in the last result is been displayed on the screen.

Problem statement:

This is C program that ask user to convey that how to pass 2d array value to function.

  1. Declare variables.
  2. Using functions.
  3. Vary loop statement.
  4. Display result on the screen.

Here is C source code for passing value to 2d array to function. The output of this program shown below. 

#include <stdio.h> 
#define M 3
#define N 5
void fstore2D(int a[][N]);
void fretrieve2D(int a[][N]);
int main()
{
     int a[M][N];
     clrscr();
     printf("Input Data in Matrix (%d X %d)\n", M, N);
     fstore2D(a);
     fretrieve2D(a);
     getch();
     return 0;
}
     void fstore2D(int a[][N])
     {
          int i, j;
          for (i = 0; i < M; ++i)
              {
                  for (j = 0; j < N; ++j)
                       scanf("%d", &a[i][j]);
              }
     }
    void fretrieve2D(int a[][N])
    {
         int i, j;
         for ( i = 0; i < M; ++i )
              {
                  for ( j = 0; j < N; ++j)
                       printf("%6d ", a[i][j]);
                       printf("\n");
              }
    } 

C Program How to Pass one Dimensional Array to Function in C

By Dinesh Thakur

In this program user ask to check that how to pass one dimensional Array to function. For this user declares the variable regarding to function. Like fstore, fretrieve, fedit these variables will be handy in criteria of function. User also define N value=5.User asks to enter data for matrix and return that all data. Here user make function for the every step like fstore, fretrieve, fedit that is been used along with loop statement that will vary the condition according to filled data. The all three functions are used for data passing next move the user prints the message for previous data and the symbol for skip or edit the data. Display result in the end for this one.

Problem statement:
This is C program that asks user to convey that how to pass data in one dimensional array.

  1. Declare array type variable.
  2. Using loop statements.
  3. Display result on the screen.

Here is C source code for passing value in one dimensional array. The output of this program shown below. 

#include <stdio.h> 
#define N 5
void fstore1D(int a[], int a_size);
void fretrieve1D(int a[], int a_size);
void fedit1D(int a[], int a_size);
int main()
{
         int a[N];
         clrscr();
         printf("Input Data into the Matrix:\n");
         fstore1D(a, N);
         fretrieve1D(a, N);
         fedit1D(a, N);
         fretrieve1D(a, N);
         return 0;
}
       void fstore1D(int a[], int n)
   {
         int i;
         for ( i = 0; i < n; ++i )
         scanf("%d", &a[i]);
   }
       void fretrieve1D(int a[], int n)
  {
        int i;
        for ( i = 0; i < n; ++i )
        printf("%6d ", a[i]);
        printf("\n");
  }
       void fedit1D(int a[], int n)
  {
       int i, q;
       for ( i = 0; i < n; ++i )
            {
                printf("Prev. data: %d\nEnter 1 to edit 0 to skip.", a[i]);
                scanf("%d", &q);
                if ( q == 1 )
                   {
                       printf("Enter new value: ");
                       scanf("%d", &a[i]);
                   }
            }
  }

C Program Find the Max Number

By Dinesh Thakur

This is c program that ask user to find out the Maximum number from given digits. User declares the required variables that use to contain the value in it. User ask to enter any five values then for loop will come in exist for evaluate the condition then if condition will use to evaluate that which number is minimum and which is maximum. Then display the result on screen as output.

Problem Statement
This is C program that ask user to find the maximum and minimum number.

  1. Declare the variable.
  2. Using methods.
  3. Display result on the screen.

Here is C source code to find maximum and minimum number. The output of this program shown below. 

#include<stdio.h>
void main()
{
      int a[5],i,max=0,min=0;
      clrscr();
      printf("Enter Five Value :");
      for(i=0;i<=4;i++)
          {
               scanf("%d",&a[i]);
          }
      for(i=0;i<=4;i++)
          {
              if(a[i]>max)
               {
                    max=a[i]; 
                   
               }
              else
               {
                    min=a[i];
                   
               }
                   
           }
                    printf("Minium is : %d\n",min);
                    printf("Maximum is : %d\n",max);
                    getch();
} 

Find the Max Number

C Program Find the Factorial of N Number

By Dinesh Thakur

This is C Program Find the Factorial of N Number. This program is for finding the factorial of N number. Two integer type variables declared with static value one of them. Here to user enter the value for finding the factorial. Then loop statement for stepping forward to find the result and (f*I) and at last to print the output on the display.

Problem Statement: 
This is C Program that has to find the factorial of N numbers.

  1. Enter the numbers.
  2. Using loop statement.
  3. Display result on the screen.

Here is source code of the C program that has to find the factorial of N numbers. The C program is successfully compiled. The program output is also shown below.

#include<stdio.h> 
main()
{
        int num,i,f=1;
        clrscr();
        printf("Enter the a Num : ");
        scanf("%d",&num);
        for(i=num;i>=1;i--)
            {
                 f=f*i;
            }
                 printf("%d",f);
                 getch();
}
Output :
Enter the a Num : 5
120

C Program Demonstrate the Use of Goto Command

By Dinesh Thakur

This program asks user to define the Goto Command. Goto command is a skip through command in C like if any condition got terminated or false the Goto command skip the process to desired location where it sets for skipping.

User takes the demo about if-else condition for defining the condition. Like user declares the variable a and b and find out the greater from a and b. user put the condition if-else if (a>b) and puts a GOTO command that prints or skip to A else GOTO b and prints a message A is greater or B is greater which condition lying true.

Problem Statement:

This is C program that asks user to demonstrate the GOTO command.

  1. Declare the variables.
  2. Using go to command.
  3. Display result on the screen.

Here is C source code for demonstrate the Go to Command. Output of this program shown below. 

#include<stdio.h>
main()
{
int a,b;
clrscr();
printf("enter the value of a,b");
scanf("%d%d",&a,&b);
if(a>b)
goto A;
 else goto B;
 A:printf("a is greater");
  goto End;
B:printf("b is greater");
  End:
getch();
}
 Demonstrate the Use of Goto Command
« Previous Page
Next Page »

Primary Sidebar

C Programming

C Programming Tutorials

  • C - History
  • C - Anatomy
  • C - Constants
  • C - Identifiers
  • C - Data Types
  • C - Libraries File
  • C - Header Files
  • C - Basic Language
  • C - Data Types Sizes
  • C - Header Files Importance
  • C - Escape Sequences
  • C - Main() Purpose
  • C - Program Procedure
  • C - Control Statements
  • C - Enumeration Constant
  • C - Add numbers
  • C - Return Statement
  • C - Avoid Goto
  • C - Command Line Arguments
  • C - Switch Case
  • C - Switch Case Limitations
  • C - getchar() and putchar()
  • C - Iteration Statements
  • C - Pass by Value and Reference
  • C - Structures and Unions
  • C - Structure
  • C - Dynamic Memory
  • C - Fgets and Fputs Functions
  • C - Gets() and Puts() Functions
  • C - Armstrong Number
  • C - Storage Classes
  • C - Fibonacci Series
  • C - Precision Setting
  • C - const Parameters

C - Variable & It's Type

  • C - Variables
  • C - Variable Lifetime
  • C - Static Variable
  • C - Register Variable
  • C - Global Variables
  • C - Auto Variables
  • C - Local Variables

C - Operator & Expressions

  • C - Operator
  • C - Boolean Operators
  • C - Bitwise Operator
  • C - Arithmetic Operators
  • C - Modulus Operator
  • C - Ternary Operator
  • C - Expressions
  • C - Arithmetic Expressions

C - Array

  • C - Arrays
  • C - Array Types
  • C - Array Characteristics
  • C - Static Arrays
  • C - Global Arrays
  • C - 3D Arrays
  • C - Dynamic Arrays
  • C - Pointer to 3D Arrays
  • C - Array Elements Hold
  • C - Arrays as Function Parameters
  • C - Accessing Matrix Elements
  • C - File Handling
  • C - Matrix Multiplication
  • C - Dynamic Memory Allocation

C - Searching & Sorting

  • C - Data Structures
  • C - Linear Search
  • C - Bubble Sort
  • C - Merge Sort
  • C - Linked List
  • C - Insertion Sort
  • C - Binary Search
  • C - Selection Sort
  • C - Quick Sort

C - Functions

  • C - Functions
  • C - Functions Advantages
  • C - Void Functions
  • C - Function Call
  • C - Default Return Value
  • C - String functions

C - Pointer

  • C - Pointers
  • C - Type Casting Of Pointers
  • C - Pointer Advantages
  • C - Pointers Initialization
  • C - Vectors and Pointers

C - Differences

  • C - C Vs C++
  • C - Formal Args. Vs Actual Args.
  • C - Keywords Vs Identifiers
  • C - Strings Vs Character Arrays
  • C - Address Vs Dereference Operator
  • C - Goto Vs longjmp
  • C - Declaring Vs Defining Variable
  • C - String Vs Array
  • C - Call by Value Vs Reference
  • C - Structure Vs Union
  • C - For Vs While loops
  • C - Compiler Vs Interpreter

C - Programs

  • C Program Standard Deviation
  • C Program Calculate Tax
  • C Program Sum Series
  • C Program Merge Arrays
  • C Program Euclid’s Algorithm
  • C Program Print Weekdays
  • C Program Sum of Digits
  • C Program Print a list
  • C Program Print Pythagorean
  • C Program Quiz program
  • C Program Display Table
  • C Program Print Comma-Separated
  • C Program Prints Prime Numbers
  • C Program for Print Integer
  • C Program Count Number
  • C Program Print Color Name
  • C Program Print Odd Numbers
  • C Program Calculate area
  • C Program for a Menu
  • C Program Add Two Vectors
  • C Program Array Addresses
  • C Program Division by Zero Error
  • C Program Compare two Dates
  • C Program Tower of Hanoi
  • C Program return 3 Numbers
  • C Program for Prime Numbers
  • C Program for Factorial
  • C Program for Palindrome

Other Links

  • C Programming - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW