• 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 Calculate Averages for Several Different Lists of Numbers

By Dinesh Thakur

 

#include <stdio.h> 
void main( )
{
        int n, count, loops, loopcount;
        float  x, average, sum;
        clrscr();
        printf ("How many lists ? " );
        scanf ("%d",&loops);
        for (loopcount = 1; loopcount <= loops; ++loopcount)
             {
                sum = 0;
                printf ( "\nList number %d\nHow many numbers? ", loopcount);
                scanf ("%d", &n) ;           
                for (count = 1; count <= n; ++count)
                    {
                        printf ( " x = " ) ;
                        scanf ( "%f", &x) ;
                        sum += x;
                    }
                       average = sum/n;
                       printf ( "\nThe average is %f\n", average) ;
              }
                       getch();
} 

Calculate Averages for Several Different Lists of Numbers

C Program A Simple Student Grades Database

By Dinesh Thakur

 

#include <stdio.h> 
#include <ctype.h>
#include <stdlib.h>
#define CLASSES 3
#define GRADES  5
int grade[CLASSES] [GRADES];
void enter_grades(void);
int get_grade(int num);
void disp_grades(int g[][GRADES]);
int main(void)
{
      char ch, str[80];
      clrscr();
      for(;;) {
      do
   {
        printf("(E)nter Grades\n");
        printf("(R)eport Grades\n");
        printf("(Q)uit\n");
        gets(str);
            ch = toupper(*str);
   }  while(ch!='E' && ch!='R' && ch!='Q');
       switch(ch)
             {
                         case 'E':
                                                enter_grades();
                                                break;
                         case 'R':
                                                disp_grades(grade);
                                                break;
                         case 'Q':
                                                exit (0);
             }
}
}
         /* Enter the student's grades. */
        void enter_grades(void)
    {
         int t, i;
         for(t=0; t<CLASSES; t++)
             {
                 printf("Class # %d:\n", t+1);
                 for(i=0; i<GRADES; ++i)
                 grade[t][i] = get_grade(i);
             }
     }
            /* Read a grade. */
            int get_grade(int num)
        {
                char s[80];
                printf("Enter Grade for Student # %d : ", num+1);
                gets(s);
                return(atoi(s));
        }
               /* Display grades. */
            void disp_grades(int g[][GRADES])
        {
             int t, i;
             for(t=0; t<CLASSES; ++t)
                 {
                     printf("Class # %d:\n", t+1);
                     for(i=0; i<GRADES; ++i)
                     printf("Student #%d is %d\n", i+1, g[t][i]);
                 }
        } 

What is Fibonacci Series in C with Example?

By Dinesh Thakur

In this tutorial, We will learn Fibonacci Series in C programming language. Fibonacci Series generates the next number by adding two last numbers. [Read more…] about What is Fibonacci Series in C with Example?

C program to Convert temperature in Fahrenheit to Celsius

By Dinesh Thakur

In this program user convert the temperature from Fahrenheit to Celsius. User declares required variables for containing the value in it. User declares the value to variables manually to make process of temperature conversion. Then while condition for laying the condition complete. In while condition the method is been used for temperature conversion that are required. Then a printing method to print result on the screen.

Problem Statement:

  1. Declaring variable.
  2. Using condition as required.
  3. Using conversion method.
  4. Display result on screen

Method for Converting Fahrenheit to Celsius.

“ Celsius = (5.0 / 9.0) * (fahr – 32.0);”

Here is C source code for Converting temperature from Fahrenheit to Celsius. The output of this program shown below. 

#include <stdio.h> 
int main(void)
{
      float fahr, celsius;
      int lower, upper, step;
      clrscr();
      lower = 0;
      upper = 300;
      step = 20;
      printf("F       C\n\n");
      fahr = lower;
      while(fahr <= upper)
             {
                  celsius = (5.0 / 9.0) * (fahr - 32.0);
                  printf("%3.0f %6.1f\n", fahr, celsius);
                  fahr = fahr + step;
             }
                  getch();
                  return 0;
} 

Fahrenheit to Celsius

Print a Table with While Loop

By Dinesh Thakur

This is C Program to Print a Table with While Loop. In this program the User asks to print a table with the use of while loop. While loop checks the condition at least once and after that it goes on. Three variables are declared to containing the value in it for condition falling. User asks to enter the value. Then using of while condition. While (a<=10) then c=b*a. and so on increment operator a++ and printing the result on the screen.

Problem Statement:
This is program where user print a table with the use of while condition.

  1. Declaring variable.
  2. Using While condition.
  3. Display result on the screen.

Here is source code of the C program where user print a table with the use of while condition. The C program is successfully compiled. The program output is also shown below.

#include<stdio.h> 
void main()
{
     int a=1,b,c;
     clrscr();
     printf("Enter Any Value : ");
     scanf("%d",&b);
     printf("Table of %d is : ",b); 
     while(a<=10)
          {
                c=b*a;
                printf(" %d ",c);  
                a++;
          }
               getch();
} 

Table with While Loop

Calculate the value of Factorial

By Dinesh Thakur

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>
void main()
{
     int num,i,f=1;
     clrscr();
     printf("Enter the a Num : ");
     scanf("%d",&num);
     i=num;
     while(i>=1)
           {
                 f=f*i;
                 i--;
           }
                 printf("%d",f);
                 getch();
} 

Write the Program For Prime Numbers?

By Dinesh Thakur

This program asks the user to find out the prime number. For this user declare the variables that use to store the value in it. User declare two int variables one of them value assign b=2 and put them on a while condition. While (a>1) then passes to control statement if (a%b==0) then a=a/b else b=b+1 and get the output on screen as result. That will show the output is prime numerical or not.

Problem Statement:

This is C Program to check whether the number is prime or not.

  1. Declaring the variable.
  2. Using conditions as required.
  3. Display result on the screen.

Here is C source code for check out the prime number. Output of this program shown below. 

#include<stdio.h> 
void main()
{
    int a,b;
    clrscr();
    printf("Enter the no. :");
    scanf("%d",&a);
    b=2;
    while(a>1)
     {
          if(a%b==0)
            {
               printf("%d",b);
               a=a/b;
            }
          else
           {
                 b=b+1;
            }
     }
                 getch();
}

Program to Find the Average of N Numbers

By Dinesh Thakur

In this program user ask to find out the average of n Numbers. User declares some variables that are used to contain the value and some elements to be assumed for computation as it is. Like variable N has to be assumed for finding average. While asking about the number quantity user also use While condition to the content. While (count < n) in condition prints the value of x and increment operator for increasing the number. In the end the method to be used for the calculating the average of N number. In the end to display the result in the end.

Problem Statement:
This is c Program that asks the user to find the average of N numbers.

  1. Declaring the Variables.
  2. Using while condition.
  3. Using average calculating method.
  4. Display result on the screen.

Here is C source code for calculating the average of N numbers. The output of this program shown below.

void main( ) 
{
      int  n, count = 1;
      float  x, average, sum = 0;
      printf("How many Numbers? " ) ;
      scanf ("%d",&n) ;
      while (count < n)
             {
                  printf ("x = " ) ;
                  scanf("%f", &x);
                  sum += x;
                  ++count;
             }
                  average = sum/n;
                  printf("\nThe Average is %f\n", average);
} 

Reverse a 10 Digit Number

By Dinesh Thakur

In this program user ask to reverse the 10 digit number. To reverse the digit user declares the variables for storing the value in it so far. User asks to put out the 10 digit value on double quoted premises. The after user declare the while condition while (a!=0). Then if the given condition rely on the situation the variable b=a%10. Then after user print out the result on the screen.

Problem Statement:
This is C program that asks user to reverse a 10 digit number.

  1. Declare variable.
  2. Using the while condition.
  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,b,r=0;
    clrscr();
    printf ("\nInput a 10 Digit Number : ");
    scanf ("%ld",&a);
    while (a!=0)
        {
                 b=a%10;
                 r=(10*r)+b;
                 a=a/10;
        }
    printf ("\nThe Reverse of the Number is : %ld",r);
    getch();
}
Output :
Input a 10 Digit Number : 1234567890
The Reverse of the Number is : 987654321

Write a Program for Number is Armstrong Number

By Dinesh Thakur

In This program user ask to find out the number is Armstrong or not. “A number is Armstrong if the sum of cubes of individual digits of a number is equal to the number itself”. User declares required variables for this operation. User uses a temp variable that will use to store the value for temporary time period. Declaring while condition while (num>0) user ask to cub=num%10, num=num/10, sum=sum+ (cub*cub*cub).

Then a if-else condition if(temp==sum) then the number is Armstrong else it will not. And after creating all instance in the end display result on the screen as output.

Problem statement:

This is C program to Check out the Number is Armstrong or not.

  1. Declaring the variables.
  2. Using while condition along with control statements.
  3. Display result on the Screen.

Here is C source code for checking out the number is Armstrong or not. The output of this program shown below. 

#include<stdio.h> 
void main()
{
   int num,temp,cub,sum=0;
   clrscr();
   printf("Enter a Number : ");
   scanf("%d",&num);
   temp=num;
   while(num>0)
     {
        cub=num%10;
        num=num/10;
        sum=sum+(cub*cub*cub);
     }
        if(temp==sum)
              printf("Number is Armstrong");
            else
              printf("Number is not Armstrong");
              getch();
}
Output :

 

Write a Program to Replace All Occurences of Letter M by N

By Dinesh Thakur

This program asks user to replace the occurrence of M by N. user declare variables and some method for replacement of occurrences. Like user ask to put file name here if condition will come in use for checking out the file exist or not if not the message will be “file can’t be open” else the while condition will use in for passing to “EOF”. If the condition match if(ch==’M’||ch==’m’) then the process will use method to replace the letter with N from M. display result on the screen at last instance.

Problem Statement:

This is C program that ask user to replace the Letter M by N.

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

Here is C source code to replace the Letter M by N. The output of this program shown below. 

#include<stdio.h>
void main()
{
     FILE *fp1;
     char ch,fname[20];
     printf("Enter file name=");
     scanf("%s",& fname);
     fp1=fopen(fname,"r+");
     if(fp1==NULL)
       {
            printf("File can't be opened");
            exit(0);
       }
            ch=fgetc(fp1);
            while(ch!=EOF)
                   {
                            if(ch=='M'||ch=='m')
                              {
                                    fseek(fp1,-1,1);
                                    fputc('N',fp1);
                              }
                                    fseek(fp1,0,1);
                                    ch=fgetc(fp1);
                  }
                                    fclose(fp1);
}

Write a Program to Count Vowels in a File Using File Handling

By Dinesh Thakur

In this program integer type variables declare (vowel,Consonent) and pointer of file (FILE *fp1;). And control statements also used if the given situation is not true than the arguments will be insufficient else it will go on. Nested if statements also come in use the next move is to if file pointer is null then source will not open. While condition tells the (ch!EOF) not equal to End of File. If condition used with the OR (!!) operator. This Will checks out the given characters match the condition. Then it’s Vowel else consonant. And in the last move it will be counted as result.

Problem Statement:-
Here in the program user has to count the Vowel with the use of file handling Concept.

  1. Checks out The Given Arguments.
  2. Using the Control Statements.
  3. Applying Required Statements.
  4. Display Result on Screen.

The C program is successfully compiled. The program output is also shown below.

#include<process.h>
#include <stdio.h>
        void main(int argc,char *argv[])
 {
         
          FILE *fp1;
          int vowel=0,consonant=0;
          char ch;
          clrscr();
          if(argc!=2)
            {
                     printf("Insufficient Arguments");
                     exit(0);
            }
          fp1=fopen(argv[1],"r");
          if(fp1==NULL)
            {
                    printf("Source can't be opened");
                    exit(0);
            }
          ch=fgetc(fp1);
          while(ch!=EOF)
                {
                       if((ch=='a')||(ch=='A')||(ch=='e')||(ch=='E')||(ch=='i')||(ch=='I')||(ch=='o') ||(ch=='O')||(ch=='u')||(ch=='U'))
                         {
                               vowel++;
                          }
                      else
                         {
                             consonant++;
                         }
                             ch=fgetc(fp1);
                }
                             printf("\n Number of vowels are = %d",vowel);
                             getch();
}

Write a Program to Count Vowels in a File Using File Handling

C Program Count the Numbers of Words in a File

By Dinesh Thakur

In this program user ask to calculate the words in file. User declare the pointer type file variable for value reference. File open function used to open the file for reading the content in file. If condition checks whether the file is null if it is the else condition comes in where while condition checks the logic (ch!=eof). Through else condition the content check to end of file. And then to print the result on display.

Problem statement:- 
This is the program where user will find out the word in the file that is been created.

  1. Create file for content storing.
  2. Using required condition for fulfilling the requirement.
  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()
{
    FILE *p;
    char ch;
    int w=1;
    clrscr();
    p=fopen("source","r");
    if(p==NULL)
     {
         printf("file not found");
      }
    else
      {
          ch=fgetc(p);
          while(ch!=EOF)
                 {
                        printf("%c",ch);
                        if(ch==' '||ch=='\n')
                          {
                               w++;
                          }
                               ch=fgetc(p);
                 }
                               printf("\nWords in a file are=%d",w);
     }
                              fclose(p);
                              getch();
}

C Program Count the Numbers of Words in a File

C Program Calculate Characters in a File

By Dinesh Thakur

 

#include<stdio.h> 
void main(int argc,char*argv[])
{
      FILE *f1;
      char ch;
      int character=0;
      clrscr();
      if(argc!=2)
        {
            printf("Insufficient Arguments");
            exit(0);
        }
      f1=fopen(argv[1],"r");
      if(f1==NULL)
        {
            printf("Source Can't be Opened");
            exit(0);
        }
            ch=fgetc(f1);
            while(ch!=EOF)
                  {
                       character++;
                       ch=fgetc(f1);
                  }
                       fclose(f1);
                       printf("No: of Characters are : %d",character);
                       getch();
}

C Program Print all Char of a File along with their Positions

By Dinesh Thakur

In this program user ask to print out the char of a file along with their positions. As user declare the variables for containing the value in it. Here user pointer type variable declaring then ask to enter the file name. if condition will checks out the has file exist or not if the file not exist the message will be file cant open if it exist the while condition will checks out all the character to EOF. With the method of display all the characters will be counted as output.

Problem Statement:

This is C program to count the character in a file.

  1. Declare the variables.
  2. Using control statements.
  3. Display output as result.

Here is C source code counting the character in a file. The output of this program shown below. 

#include<stdio.h>
void main()
{
      FILE *fp;
      char ch,fname[20];
      int n;
      printf("Enter file Name :");
      gets(fname);
      fp=fopen(fname,"r");
      if(fp==NULL)
        {
              printf("file can't be opened");
             exit(0);
        }
             fseek(fp,0,0);
             ch=fgetc(fp);
             while(ch!=EOF)
                     {
                           n=ftell(fp);
                           printf("%c ",ch);
                           printf("%d \n",n);
                           ch=fgetc(fp);
                    }
                           fclose(fp);
}

Char of a File along with their Positions

C Program Convert all Characters of File to Uppercase

By Dinesh Thakur

In this program user asks to convert all characters that are contained in a file to uppercase. To make this process user need to make a file and fill up some characters in it for operation. User declares the variables. And then put up a function to open file and also fill up character in it. Then if condition checks whether the file exists or not if the condition goes true then the program will terminate because file does not exist or then after while condition checks out the file and character and put up the condition to convert it into uppercase. Display the result on the screen.

Problem Statement:

This is c program that asks user to converts all the character in file into Upper case.

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

Here is C source code for Converting the Character into Uppercase. The output of this program shown below. 

#include<stdio.h>
#include<ctype.h>
void main()
{
         FILE*f1;
         char ch,fname[20],d;
         clrscr();
         f1=fopen(fname,"w");
         printf("\nEnter File Name :");
         scanf("%s",& fname);
         f1=fopen(fname,"r");
         if(f1==NULL)
            {
                  printf("File can't be Opened");
                  exit();
             }
                  while(ch!=EOF)
                         {
                               d=toupper(ch);
                               printf("%c",d);
                               ch=fgetc(f1);
                         }
                              fclose(f1);
                              getch();
} 

Convert all Characters of File to Uppercase

C Program Compute Powers of Two and Print With Different Integer Types

By Dinesh Thakur

 

#include <stdio.h>
int main()
{
       int i=0;
       unsigned x=1;
       int intx=1;      /* added to original code so both can be seen at the same time*/
       clrscr();
         while (i <20)
           {
                printf("%8d:%8u:%8d\n",i,x,intx);
                /* %u is unsigned decimal format can only print as far as 2^14*/
                ++i;
                x *= 2;
                intx *= 2;
          }
               x= -1;
               printf("\n\nminus one = %8d%8u\n\n", x, x);
               /* x printed out as integer is -1 but as unsigned format prints 65535 */
               getch();
               return 0;
} 

Compute Powers

C Program A User-Defined Function to Find Factorial of a Number

By Dinesh Thakur

In this example, a for loop is used to determine the factorial of a given number, a. The variable a itself is used as the loop variable. As the value of variable a will be initialized when the scanf statement is executed, the initial expression in the for loop is not required and is omitted.

Note that we have avoided a separate loop variable, reducing the memory requirement of this program. However, the original value of variable a is not available after the loop is executed. This approach is particularly suitable in a function that calculates and returns the value of factorial of a given number.

#include <stdio.h>
#include <conio.h>
void main ()
{
           int a;
           long f,fact();
           clrscr();
           printf ("\n Enter a Number : ");
           scanf ("%d",&a);
           f=fact(a);
           printf ("\n The Factorial of %d is : %ld",a,f);
           getch();
}
       long fact(int b)
 {
     int i;
     long f=1;
     for (i=1;i<=b;i++)
            f=f*i;
            return(f);
}
Output :
Enter a Number : 5
The Factorial of 5 is : 120

C Program Swap A Two Number Through Function

By Dinesh Thakur

In this Program user asks to Swap a two number through function. User declares the pointer type variable for interchanging the value of two variables. User asks to enter the value. User make a function named swap that will be called in other class. Then a printing message for swapped value to the function then returns a value.

In other move the function swap is been called for interchanging the values to each other. In this criteria user declare a variable temp that will use to store a temporary time value for trespassing with each other variable like mentioned in the program temp=*d1 and then to other variable. In the last instance the result is been displayed on the screen.

Problem statement:
This is Program that asks user to interchange the value with each other variable through function.

  1. Declaring required variables.
  2. Making function.
  3. Enters value.
  4. Call function.
  5. And display result on the screen.

Here is C source code for interchanging the value with each other through function Output of this program shown below. 

#include <stdio.h>
//#include <string.h>
void swap (double *d1, double *d2);          
int main ()
{
            double num1, num2;
            clrscr();
            printf("Type in 2 Numbers : ");
            scanf("%lf%lf", &num1,&num2);
            swap(&num1,&num2);
            printf("\nThe two Numbers Swapped are %lf, %lf", num1, num2);
            getch();
            return 0;
}
void swap (double *d1, double *d2)
        {
            double temp;
            temp=*d1;
            *d1=*d2;
            *d2=temp;
         } 

Swap A Two Number Through Function

C Program User-defined Function to Search For 1st Occurrence of Char in String

By Dinesh Thakur

The strchr function finds the first occurrence of a specified character in a string, If the specified character is found, the function returns a pointer to that character; otherwise, it returns a NULL pointer. Initially, the strchr function is used to locate the position of the first ‘ l ‘ character in strings and its address is assigned to pointer result.

#include <stdio.h>
char *strchr(char *string, char letter);
int main()
{
            int i;
            char strings[2][30]={"hello world","C programming"};
            char letters[]={'l','z'},*result;
            clrscr();
            for (i=0;i<2;i++)
                {    
                     if(*(result=strchr(strings[i],letters[i]))!=NULL)
                       printf("\n\n\"%s\" was scanned for \'%c\'.\nFunction returned:->  %s",strings[i],letters[i],result);
              else
                       printf("\n\n\'%c\' was not found in \"%s\"",letters[i],strings[i]);
                }  
                       getch();
                       return 0;
}
                       char *strchr(char *string, char letter)
                   {
                       char *ptr=NULL;
                       while (*string!=letter && *string!=NULL)
                                ptr=++string;
                                return (ptr);
                   } 

Search For 1st Occurrence of Char in String

C Program Find Sum of Two number Through Function

By Dinesh Thakur

This is C Program Find Sum of Two number Through Function. In this program user asks to find the sum of two numbers with use of function in other words Polymorphism. The function calling procedure will use in this program to find the sum of two numbers. First user ask the numbers which are use to add. Then it declares a function sum (a,b). The next move it call the function sum with formal arguments int x, int y and int z=x+y in this procedure the value call from the upper class but add in other class. And in the last the result print on the screen.

Problem Statement: 
In this program the user asks to find the sum of two numbers through function.

  1. Enter the value.
  2. Declare Function.
  3. Call the Function.
  4. Display result on the screen.

Here is source code of the C program that Find the sum of two numbers through function. The C program is successfully compiled. The program output is also shown below.

#include<stdio.h> 
void main()
{
       int a,b;
       clrscr();
       printf("Enter Two Number : ");
       scanf("%d%d",&a,&b);
       sum(a,b);
       getch();
}
      sum(int x,int y)
  {
       int z;
       z=x+y;
       printf("Sum of Two Number is : %d",z);
       return 0;
}
Output :
Enter Two Number : 10 20
Sum of Two Number is : 30

C Program Calculate Sum Multiply,Division Through Function

By Dinesh Thakur

In this program user asks to find the sum, division, multiply of two numbers with use of function in other words Polymorphism. The function calling procedure will use in this program to find the sum of two numbers. First user asks the numbers which are use to add, divide or multi. Then it declares a function sum, multi, divide (a,b). The next move it call the function sum with formal arguments int x, int y in this procedure the value call from the upper class but add in other class. And in the last the result print on the screen.

Problem Statement:

In this program the user asks to find the sum of two numbers through function.

  1. Enter the value.
  2. Declare Function.
  3. Call the Function.
  4. Display result on the screen.

Here is source code of the C program that Find the sum, multi, division of two numbers through function. The C program is successfully compiled. The program output is also shown below. 

#include<stdio.h>
void main()
{
    int a,b,c,d,e,f;
    clrscr();
    printf("Enter Two Values :");
    scanf("%d%d",&a,&b);
    sum(a,b);
    mult(a,b);
    div(a,b);
    getch();
}
    sum(int x,int y)
      {
            int z;
            z=x+y;
            printf("Addtion : %d\n",z);
            return 0;
      }
    mult(int x,int y)
     {
            int z;
            z=x*y;
            printf("Multiply : %d\n",z);
            return 0;
      }
    div(int x,int y)
     {
            int z;
            z=x/y;
            printf("Div : %d\n",z);
            return 0;
      }



Calculate Sum Multiply,Division Through Function

C Program Calculate HCF of 2 Numbers using Functions

By Dinesh Thakur

In this program user ask to find out the HCF (highest common factor) using function. As declaring required variable user ask to enter the value. User made a function named “HCF”. Then using control statement if(a>b) the HCF (a,b) else (b,a) after fetching the HCF through getch(). 

In the next move user calls the function that made HCF. Here user also declare a variable named r=1. And a while condition too. While(r! =0) if the condition got true than the value must be fetch out from use of modulus operator. After that interchange the value within x, y or r. display the result on the screen.

Problem Statement:

This is C program that asks user to find out the HCF using function.

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

This is C program here user need to find out the HCF using function Method. Output of this program shown below. 

#include<stdio.h> 
int hcf(int x,int y);
void main()
{
    int a,b,d;
    clrscr();
    printf("Enter 2 Numbers : ");
    scanf("%d%d",&a,&b);
    if(a>b)
      {
           d=hcf(a,b);
      }
    else
     {
           d= hcf(b,a);
     }
           printf("HCF is= %d",d);
           getch();
}
    int hcf(int x,int y)
    {
       int r=1;
       while(r!=0)
          {
               r=x%y;
               x=y;
               y=r;
          }
               return(x);
    } 

Calculate HCF of 2 Numbers using Functions

C Program Calculate Factorial of a Number using Recursion

By Dinesh Thakur

Consider the program given below, written using the top-down approach, that calculates the factorial of a given integer number using function fact defined in Example. Function fact is called in the main function from a printf function call and the int value returned by it is printed using the %d conversion specification.

Observe that the main function is defined first followed by the function fact, which is called before it is defined. Thus, we need to declare fact in the main function or before it. In the program given above, fact is declared before the main function. The program output is given below.

#include<stdio.h>
int fact(int);
void main()
{
        int n,t;
        clrscr();
        printf("Enter any Number : ");
        scanf("%d",& n);
        t=fact(n);
        printf("Factorial of %d is : %d",n,t);
        getch();
}
        int fact(int a)
      {
               int p;
               if(a==1)
                        return(1);
               else
               {
                        p=a*fact(a-1);
                        return(p);
               }
      } 

Factorial of a Number using Recursion

C Program For Bank Operation

By Dinesh Thakur

 This is C program that asks user to create the bank system criteria through programming. User will use switch statement to create these operation. From this user can select through their choices. User also declares variables for the storing value. User also declares some functions like void creation (), void deposit (), void withdraw (). These function will used during calling operation.

Along with this user also declare structure type variables too. In operation using switch statement user define while condition. Using printing method that will appear on the screen user create a switch statement for the Case operation here user made case for every operation like create, deposit, with draw etc. 
For creating procedure an account in bank system user call the function void create () like this user also call the void deposit () function for depositing the fund here in this procedure user uses the control statement where it will verify the account no if it will be correct the ok otherwise else condition will terminate the condition. As well as void withdraw () for withdrawing the cash here also verification will be take place to check the condition of account viability. The next one is void bal () for balance enquiry too. In the end all the criteria will be on the screen as result.

Problem Statement:
This is c program that will ask user to create a banking system.

  1. Creating functions.
  2. Using switch statements.
  3. Declaring variables.
  4. Using control statements.
  5. Display result on the screen.

Here is C source code for creating the banking system. The output of this program shown below. 

#include<stdio.h> 
#include<conio.h>
void creation();
void deposit();
void withdraw();
void bal();
int a=0,i = 101;
struct bank
{
        int no;
        char name[20];
        float bal;
        float dep;
}s[20];
        void main()
       {
                  int ch;
                  while(1)
                        {
                              clrscr();
                              printf("\n*********************");
                              printf("\n BANKING ");
                              printf("\n*********************");
                              printf("\n1-Creation");
                              printf("\n2-Deposit");
                              printf("\n3-Withdraw");
                              printf("\n4-Balance Enquiry");
                              printf("\n5-Exit");
                              printf("\nEnter your choice");
                              scanf("%d",&ch);
                              switch(ch)
                                       {
                                              case 1: creation();
                                                         break;
                                              case 2: deposit();
                                                         break;
                                              case 3: withdraw();
                                                         break;
                                              case 4: bal();
                                                         break;
                                              case 5: exit(0);
                                                         defalut: printf("Enter 1-5 only");
                                                         getch();
                                        }
                         }
        }
             void creation()
        {
                   printf("\n*************************************");
                   printf("\n ACCOUNT CREATION ");
                   printf("\n*************************************");
                   printf("\nYour Account Number is :%d",i);
                              s[a].no = i;
                   printf("\nEnter your Name:");
                              scanf("%s",s[a].name);
                   printf("\nYour Deposit is Minimum Rs.500");
                              s[a].dep=500;
                              a++;
                              i++;
                              getch();
         }
              void deposit()
        {
                   int no,b=0,m=0;
                   float aa;
                   printf("\n*************************************");
                   printf("\n DEPOSIT ");
                   printf("\n*************************************");
                   printf("\nEnter your Account Number");
                   scanf("%d",&no);
                   for(b=0;b<i;b++)
                       {
                           if(s[b].no == no)
                               m = b;
                       }
                           if(s[m].no == no)
                             {
                                        printf("\n Account Number : %d",s[m].no);
                                        printf("\n Name : %s",s[m].name);
                                        printf("\n Deposit : %f",s[m].dep);
                                        printf("\n How Much Deposited Now:");
                                        scanf("%f",&aa);
                                        s[m].dep+=aa;
                                        printf("\nDeposit Amount is :%f",s[m].dep);
                                        getch();
                             }
                            else
                             {
                                       printf("\nACCOUNT NUMBER IS INVALID");
                                       getch();
                              }
         }
             void withdraw()
         {
                    int no,b=0,m=0;
                    float aa;
                    printf("\n*************************************");
                    printf("\n WITHDRAW ");
                    printf("\n*************************************");
                    printf("\nEnter your Account Number");
                    scanf("%d",&no);
                    for(b=0;b<i;b++)
                        {
                               if(s[b].no == no)
                                 m = b;
                        }
                              if(s[m].no == no)
                                 {
                                        printf("\n Account Number : %d",s[m].no);
                                        printf("\n Name : %s",s[m].name);
                                        printf("\n Deposit : %f",s[m].dep);
                                        printf("\n How Much Withdraw Now:");
                                        scanf("%f",&aa);
                                        if(s[m].dep<aa+500)
                                           {
                                                  printf("\nCANNOT WITHDRAW YOUR ACCOUNT HAS MINIMUM BALANCE");
                                                  getch();
                                           }
                                          else
                                           {
                                                  s[m].dep-=aa;
                                                  printf("\nThe Balance Amount is:%f",s[m].dep);
                                            }
                                 }
                               else
                                {
                                      printf("INVALID");
                                      getch();
                                }
                                      getch();
          }
                void bal()
          {
                  int no,b=0,m=0;
                  float aa;
                  printf("\n*************************************");
                  printf("\n BALANCE ENQUIRY ");
                  printf("\n*************************************");
                  printf("\nEnter your Account Number");
                  scanf("%d",&no);
                  for(b=0;b<i;b++)       
                      {
                           if(s[b].no == no)
                             m = b;
                      }
                           if(s[m].no==no)
                              {
                                    printf("\n Account Number : %d",s[m].no);
                                    printf("\n Name : %s",s[m].name);
                                    printf("\n Deposit : %f",s[m].dep);
                                    getch();
                              }
                             else
                             {
                                    printf("INVALID");
                                    getch();
                              }
            }

Bank Operation

C Program Using Structure to Calculate Marks of 10 Students in Different Subjects

By Dinesh Thakur

In this program, a structure (student) is created which contains name,subject and marks as its data member. Then, an array of structure of 10 elements is created. Then, data (name, sub and marks) for 10 elements is asked to user and stored in array of structure. Finally, the data entered by user is displayed.

Problem Statement:
The annual examination is conducted for 10 students for three subjects. Write a program to read the data and determine the following:
(a) Total marks obtained by each student.
(b) The highest marks in each subject and the marks. of the student who secured it.
(c) The student who obtained the highest total marks.
Here is source code of the C program to calculate The Marks and the grades of Students . The C program is successfully compiled. The program output is also shown below.

#include<stdio.h>
        struct student
        {
          int sub1;
          int sub2;
          int sub3;
        };
            void main()
        {
             struct student s[10];
             int i,total=0;
             clrscr();
             for(i=0;i<=2;i++)
                 {
                        printf("\nEnter Marks in Three Subjects = ");
                        scanf("%d%d%d",& s[i].sub1,&s[i].sub2,&s[i].sub3);
                        total=s[i].sub1+s[i].sub2+s[i].sub3;
                        printf("\nTotal marks of s[%d] Student= %d",i,total);
                 }
                        getch();
         }

Calculate Marks of 10 Students

C Program to Sort the Record of Student Merit Wise

By Dinesh Thakur

In this program user ask to sort the record of multiple students merit wise. In this program structure type variable declared and a temp variable for temporary value storing. User need to establish the merit chart for sorting them. For this process user will use loop statement where user will calculate the data of students that are define on variable value. Loop statement will print all the data about student (roll no,score,name etc.). From the structure type variable.

The temp variable will hold the value for trespass the data to other variable. That after the loop process will admire the data according to Merit condition as the condition got true the sorted list will be on the screen. In the end sorted data will be print out as the result.
Problem statement:
This is c program that ask user to sort student data merit wise.

  1. Declaring variables.
  2. Using loop Statement.
  3. Print out the result on the screen.

Here is C source code for Sorting the Record of student Merit wise. The output of this program shown below.

[Read more…] about C Program to Sort the Record of Student Merit Wise

C Program Write a Program to add,subtract and multiply two complex number

By Dinesh Thakur

[Read more…] about C Program Write a Program to add,subtract and multiply two complex number

C Program to Swap Two Numbers Using Pointer

By Dinesh Thakur

 This is C Program to Swap Two Numbers Using Pointer. In this program the two numbers to be swapped from each other place with the use of pointer this concept works on the address reference. In program the variables declare for storing the value in it. Here a variable named ‘temp’ also declared with the use of only two numbers the swapping will happen interference of temp variable the first number shifted to temp and then to other variable the reverse phase will be on the move to swap both numbers. And other functionality also comes in light for displaying the result on the screen.

Problem Statement: 
This is C Program to Swap Two Numbers Using Pointer condition.

  1. Declaring variable pointer type.
  2. Using swap condition.
  3. Display result on the screen.

Here is source code of the C program to Swap Two Numbers Using Pointer condition. The C program is successfully compiled. The program output is also shown below.

#include <stdio.h> 
#include <conio.h>
void swap(float *d1 , float *d2)
{
    float temp;
    temp=*d1;
    *d1=*d2;
    *d2=temp;
}
void main()
{
    float a,b;
    clrscr();
    printf("Enter number a :");
    scanf("%f", &a);
    printf("\nEnter number b :");
    scanf("%f", &b);
    printf("\nBefore Swapping\n");
    printf("\na Contain %6.2f ",a);
    printf("\nb Contain %6.2f ",b);
    swap(&a,&b);
    printf("\nAfter Swapping\n");
    printf("\na Contain %6.2f ",a);
    printf("\nb Contain %6.2f ",b);
    getch();
}

Swap Two Numbers Using Pointer

C Program Conver a Value to Pointer Check Address of Variable

By Dinesh Thakur

In this program user ask to convert a value to pointer check address of variable. User declares some variables for this to contain the value in it. User declare <math.h> header file for math functions like pi etc. the type of variable is differ like some are double, integer, char type etc. user print out the method for conversing in pointer type to using all the method for conversion display the result as output.

Problem Statement:

This is C program to convert the value into pointer.

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

Here is C source code to convert the value into pointer. The output of this program shown below. 

#include <stdio.h>
#include <math.h>
int main ()
            {          
            char                 *pc = 0;
            int                    *pi = 0;
            double       *pd = 0;
  printf("%8d%8d%8d\n",*pc,*pi,*pd);
  printf("%8d%8d%8d\n", pc+1, pi+1, pd+1);
  printf("%8d%8d%8d\n", pc+3, pi+5, pd+7);        
            return 0;
            }
 Convert a Value to Pointer Check Address of Variable
« 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