Online Examination System for all learner!!! coming soon..

C : Program to check given number is armstrong or not.

Code:

#include<stdio.h>
#include<conio.h>
main()
{
        int n,x;
        printf("Enter a number:");  
        scanf("%d",&n);
        x=armstrong(n);
        if(x==n)
                printf("Arm strong");
        else
                printf("Not arm strong");
}

int armstrong(int num)
{
        int sum=0,r;
        while(num!=0)
        {
                r=num%10;
                num=num/10;
                sum=sum+(r*r*r);
        }
        return sum;
}


Output:

Enter a number:1

Arm strong 

C : Program to calculate the prime factors of a numbers.

Program to calculate the prime factors of a numbers.


#include<stdio.h>
#include<conio.h>
main()
{
        int x,n;
        printf("Enter a number :");
        scanf("%d",&n);
        prime_factors(n);
}
int prime_factors(int n)
{
        int i=1,k;
        while(i<=n)
        {
                if(n%i==0)
                {
                        k=check_prime(i);
                        if(k!=0)
                                printf("%d ",k);
                }
                i++;
        }
}
int check_prime(int n)
{
        int i=1;
        int c=0;
        while(i<=n)
        {
                if(n%i==0)
                        c++;
                i++;
        }
        if(c==2)
                return n;
        else
                return 0;
}

C : Program to check the number is strong number or not.

Code:

#include<stdio.h>
#include<conio.h>

main()
{
        int x,n;
        printf("Enter a number :");
        scanf("%d",&n);
        x=strong(n);
        if(x==n)
                printf("Strong");
        else
                printf("Not strong");
}
int strong(int n)
{
        int s=0,r,f;
        while(n>0)
        {
                r=n%10;
                f=fact(r);
                s=s+f;
                n=n/10;
        }
        return s;
}
int fact(int n)
{
        int f=1;
        while(n>0)
        {
                f=f*n;
                n--;
        }
        return f;
}

Output:

C : Program to reverse a number.

Code:

#include<stdio.h>
#include<conio.h>

main()
{
        int x,n;
        printf("Enter a number :");
        scanf("%d",&n);
        x=reverse(n);
        printf("%d",x);
}
int reverse(int n)
{
        int s=0;
        while(n>0)
        {
                s=s *10 + n%10;
                n=n/10;
        }
        return s;
}


Output:

Enter a number :56
65
--------------------------------
Process exited after 8.599 seconds with return value 2
Press any key to continue . . .

C : Program to calculate the sum digits of a number.

Code:

#include<stdio.h>
#include<conio.h>
main()
{
        int x,n;
        printf("Enter a number :");
        scanf("%d",&n);
        x=sum_digit(n);
        printf("%d",x);
}
int sum_digit(int n)
{
        int s=0;
        while(n>0)
        {
                s=s + n%10;
                n=n/10;
        }
        return s;
}

Output:

C : Program to calculate the factorial of a number.

Program to calculate the factorial of a number.


#include<stdio.h>
#include<conio.h>
main()
{
        int x,n;
        printf("Enter a number :");
        scanf("%d",&n);
        x=fact(n);
        printf("%d",x);
}
int fact(int n)
{
        int f=1;
        while(n>0)
        {
                f=f*n;
                n--;
        }
        return f;

}

C : Basic structure of C program

Basic structure of C program





Documentation Section
This section consists of comment lines which include the name of programmer, the author and other details like time and date of writing the program. Documentation section helps anyone to get an overview of the program.

Link Section
The link section consists of the header files of the functions that are used in the program. It provides instructions to the compiler to link functions from the system library.

Definition Section
All the symbolic constants are written in definition section. Macros are known as symbolic constants.

Global Declaration Section
The global variables that can be used anywhere in the program are declared in global declaration section. This section also declares the user defined functions.

main() Function Section
It is necessary have one main() function section in every C program. This section contains two parts, declaration and executable part. The declaration part declares all the variables that are used in executable part. These two parts must be written in between the opening and closing braces. Each statement in the declaration and executable part must end with a semicolon (;). The execution of program starts at opening braces and ends at closing braces.

Subprogram Section
The subprogram section contains all the user defined functions that are used to perform a specific task. These user defined functions are called in the main() function.

C : Simple Calculator

Make Simple Calculator in C

To make a simple calculator in C programming which performs basic four mathematical operations, use the switch case to identify the input operator to perform required calculation then display the result

C Programming Code to Make Simple Calculate

Following is a simple C program which is a menu-driven program based on simple calculation like addition, subtraction, multiplication and division according to user's choice:

EXAMPLE C PROGRAM FOR PRIME NUMBER:

#include <stdio.h>
int main()
{
   int i, num, p = 0;
   printf("Please enter a number: \n");
   scanf("%d", &num);
   for(i=1; i<=num; i++)
   {
      if(num%i==0)
      {
         p++;
      }
   }
   if(p==2)
   {
      printf("Entered number is %d "\
             "and it is a prime number.",num);
   }
   else
   {
      printf("Entered number is %d "\
             "and it is not a prime number.",num);
   }
}

OUTPUT OF C PROGRAM FOR PRIME NUMBER:

Please enter a number: 13
Entered number is 13 and it is a prime number.

C Programming Online Test 1

Following quiz provides Multiple Choice Questions (MCQs) related to C Programming Framework. You will have to read all the given answ...