Our Blog Contain Detail about Some Technical Aspect like Programming, Blogger, Tools and Tip, Suggestion, Motivational, Health, Program in C and Java, Html

Write a program to display digit of a five-digit no

 Write a program to receive a five-digit no and display as like 24689:

2

4

6

8

9



Program in C Language

#include<stdio.h>

#include<conio.h>

#include <math.h>

void main()

{

      int num,i;


    printf ("Input a five digit number: ");

    scanf ("%d", &num);


    for (i = 4; num > 0; i--)

    {

        printf ("%d", num / (int)pow (10, i));

        num = num % (int) pow (10, i);

        printf ("\n");

    }

    getch();

}

Share:

Write a program to draw the following figure

Write a program to draw the following figure:

3 2 1

21

1

*

**

***



Program in C Language

#include<stdio.h>
#include<conio.h>
void main()
{
     int i,j;
     for(i=3;i>=1;i--)
     {

           for(j=i;j>=1;j--)
          {
           printf("%d",j);
          }
          printf("\n");
     }
     for(i=1;i<=3;i++)
     {

           for(j=1;j<=i;j++)
          {
           printf("*");
          }
          printf("\n");
     }
getch();
}


Share:

Write a function that return sum of all the odd digits of a given positive no entered through keyboard

Write a function that return sum of all the odd digits of a given positive no entered through keyboard



#include<stdio.h>
#include<conio.h>
int sumodd(int num)
{
     int sum=0,i;

     for(i=0;i<=num;i++)
     {
          if(i%2!=0)
          {
               sum=sum+i;
               printf("%d,",i);
          }
     }
     return sum;
}

void main()
{
 int n,sum;
printf("enter a number\n");
scanf("%d",&n);
sum=sumodd(n);
printf("\n sum of odd number is %d",sum);
getch();
}

Share:

Write a program to find sum of Fibonacci series using function.

 Write a program to find sum of Fibonacci series using function.



#include<conio.h>
#include<stdio.h>
int sumfab(int num)
{
     int a=1,b=1,sum=2,i,c;
     printf("%d,%d,",a,b);
     for(i=3;i<=num;i++)
     {
          c=a+b;
          sum=sum+c;
          a=b;
          b=c;
          printf("%d,",c);
     }
     return sum;
}

void main()
{

     int n,sum;
     printf("enter a number \n");
     scanf("%d",&n);
     sum=sumfab(n);
     printf("the sum is %d",sum);
     getch();
}

Share:

Write a program to calculate the factorial for given number using function.

 Write a program to calculate the factorial for given number using function.



Factorial for given number without using function

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

void main()
{
     int i,n;
     int fact=1;
     printf("enter the number\n");
     scanf("%d",&n);
     for(i=n;i>=1;i--)
     {
          fact=fact*i;
     }
     printf("%d",fact);

}

Factorial for given number using function

#include<stdio.h>
#include<conio.h>
int fact(int num)
{

     int f=1,i;
     for(i=1;i<=num;i++)
     {
          f=f*i;
     }
     return f;
}

void main()
{
     int fa,n;
     printf("\n enter the number \n");
     scanf("%d",&n);
     fa=fact(n);
     printf("\n Factorial of number%d is %d",n,fa);
     getch();
}

Share:

Write a program to print the entire prime no between 1 and 300.

Write a program to print the entire prime no between 1 and 300. 



Program in C language

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

int IsPrime(int num)
{
     int i,b=1;
     for(i=2;i<num;i++)
     {
          if(num%i==0)
          {
               b=0;
               break;
          }

     }

     return b;

}

void main()
{
int i;

for(i=2;i<=100;i++)
{
 if(IsPrime(i))
{

     printf("%d\n",i);
}
}

}

Share:

Write a program to generate sum of series 1!+2!+3!+--------------n!

Write a program to generate sum of series 1!+2!+3!+--------------n!



In order generate sum of series 1!+2!+3!+--------------n! there is need to take help of function that can able to calculate the factorial of any number 


Program in C language

#include<stdio.h>

#include<conio.h>


int fact(int n)

{


     if(n==1)

          return 1;

     else

          return n*fact(n-1);

}


void main()

{


     int n,factorial,sum=0,i;

     printf("enter a number \n");

     scanf("%d",&n);

     for(i=1;i<=n;i++)

     {

        factorial=fact(i);

        sum=sum+factorial;

     }


     printf("Sum of the given series is %d",sum);

     getch();

}


Share:

Write a program to print out all the Armstrong number between 100 and 500.

Write a program to print out all the Armstrong number between 100 and 500.



Program in C Language

#include<stdio.h>

#include<conio.h>
int checkams(int num);
void main()
{
     int i;
     for(i=100;i<=500;i++)
     {
          if(checkams(i))
          {
               printf("%d\n",i);
          }
     }
     getch();
}


int checkams(int num)
{

   int digit,sum=0,temp;
  // printf("enter an number\n");
  // scanf("%d",&num);
   temp=num;
   while(num!=0)
   {
        digit=num%10;
        num=num/10;
        sum=sum+digit*digit*digit;
   }
   if(sum==temp)
   {
        return 1;
   }
   else
   {
        return 0;
   }

}


Share:

Write a program to find the largest of three numbers using nested if else

 Write a program to find the largest of three numbers using nested if else.



INDEX
  • Introduction to problem
  • Algorithm 
  • Flowchart
  • Program in C language
  • Output

Introduction to Program

In this problem statement, we have three number and out of these three number we have to find, which is bigger or largest. this can be achieve by comparing these three number with each other.

Algorithm

Step1: declare three variable named A, B and C

Step2: Read the value of A, B and C from user

Step3: if A>B then
                if A > C then
                print A is greater
                   otherwise
                print C is greater
            otherwise
                 if B > C then
                print B is greater
                   otherwise
                print C is greater
Step4: Exit

Flow chart



Program in C language

#include<stdio.h>
#include<conio.h>
void main()
{
     int num1,num2,num3;
     printf("enter any three number\n");
     scanf("%d %d %d",&num1,&num2,&num3);
     if(num1>num2)
     {
          if(num1>num3)
          {
            printf("%d is greater than %d ,%d",num1,num2,num3);
          }
          else
          {
            printf("%d is greater than %d ,%d",num3,num1,num2);
          }
     }
     else
     {
         if(num2>num3)
         {
             printf("%d is greater than %d ,%d",num2,num1,num3);
         }
         else
         {
             printf("%d is greater than %d ,%d",num3,num1,num2);
         }
     }
}


OutPut

enter any three number
23 
3
24

24 is greater than 23, 3
Share:

Write a program in C to find whether the number is Armstrong number.

 Write a program to find whether the number is Armstrong number


Index

  • Introduction
  • Algorithm of Problem 
  • Flow Chart 
  • Program in C 
  • Out Put

Introduction 

Armstrong number is the number whose digits cube is sum together we get the same number ex 370 in this number we have three digits 3 , 7 , 0, if we calculate the cube of each digit cube of 3 is 27, similarly cube of 7 is 343 and 0 is 0. if we add the resulted value 343+27+0=370 as answer is same as number so number is Armstrong number.

Algorithm of solving given problem

Step 1: Declare three variable digit, sum , num  
Step 2: Take  a number as input from user
Step 3: initialize the value of sum = 0 and set temp = num
Step 4: Repeat step 5 to 7  until num !=0
Step 5: Set digit = num %10;
Step 6: Set num=num / 10;
Step 7: Set sum=sum + digit * digit * digit.
Step 8: If sum == temp than
           print number is arm strong
           otherwise
           print number is not arm strong 
Step 9: Exit

Flow Chart

Flow chart 


Program in C language


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

void main()
{
int digit,sum=0,temp,num;
  printf("enter an number\n");
  scanf("%d",&num);
   temp=num;
   while(num!=0)
   {
        digit=num%10;
        num=num/10;
        sum=sum+digit*digit*digit;
   }
   if(sum==temp)
   {
       printf("number is Armstrong");
   }
   else
   {
        printf("number is not Armstrong");
   }

}

OUTPUT

enter an number
370
number is Armstrong

enter an number
370
number is not Armstrong
Share:

Write a Program in C to calculate the Net Salary if basic salary is given

Basic salary of an employee is input through the keyboard. The DA is 25% of the basic salary while the HRA is 15% of the basic salary. Provident Fund is deducted at the rate of 10% of the gross salary (BS+DA+HRA). Program to calculate the Net Salary.


Index

  • Introduction to Problem
  • Algorithm to solve the Problem
  • Flow chart 
  • Program in C language 
  • Out Put

Introduction to Problem

Basic salary of an employee is input through the keyboard. The DA is 25% of the basic salary while the HRA is 15% of the basic salary. Provident Fund is deducted at the rate of 10% of the gross salary (BS+DA+HRA). Program to calculate the Net Salary.

as per the instruction calculate the gross salary there is need to calculate DA and HRA is need to be calculated. after that Net Salary is calculated by deducting the PF from it.

Algorithm to solve the problem

Step 1: Take Basic salary as a Input from the user.
Step 2: then calculate the DA of basic salary using below formula 
 DA = (Basic salary * 25)/100

Step 3: then calculate the HRA of basic salary using below formula

HRA= (Basic salary * 15) / 100

Step 4: then we are going to calculate Gross Salary using below formula

            GS = BS + DA + HRA

Step 5: after that Provident fund is deducted using below formula

             Net Salary=GS - (GS*10)/100;

Step 6: Print the value of Net Salary

Step 7: Exit


Flow Chart




Program in C language 

#include<stdio.h>
#include<conio.h>
void main()
{
     double BS;
     double DA,HRA,GS,NS,PF;
     printf("Enter yours salary\n");
     scanf("%lf",&BS);
     DA= (BS * 25)/100;
     HRA= (BS * 15)/100;
     GS= BS+DA+HAR;
     PF= (GS * 10)/100;
     NS=GS-PF;
     Print("Yours Net Salary is %lf",NS);
     getch();



            Out put




Share:

Write a program to calculate the area of triangle using formula at=√s(sa)(s-b)(s-c)


 Write a program to calculate the area of triangle using formula at=√s(sa)(s-b)(s-c)



Index 
  • Introduction 
  • Algorithm of give Problem 
  • Flow Chart
  • Program in C language 
  • Out put 

Introduction 

In this Problem Statement we have to calculate the area of triangle using Heron’s Formula

at=√s(s-a)(s-b)(s-c)

where a, b , c are the side of triangle

S =(a+b+c)/2 it is semi Perimeter

There logic is that first of all we are going to take input from the user in order to calculate the value of area of triangle

so see the algorithm for above problem statement

Algorithm of give Problem

Input: Three side of triangle 
Output: Area of triangle using given formula

Step1: Take the side of triangle as input from user let a, b, s.
Step2: Now Calculate the value of S using below formula

            S =(a+b+c)/2

 Step3: Now calculate the value of area of triangle using below formula

          Area = sqrt(S * (S-a) * (S-b) * (S-c));

Note: in order to calculate Square Root we make use of Function Sqrt
from header file math.h

Step4: Print the value of Area
Step5: Exit.

Flow Chart







Program in C language

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

void main()
{
     double a,b,c,at,temp,S;

     printf("Enter the size of side of triangle\n");
     scanf("%lf %lf %lf",&a,&b,&c);
     S=(a+b+c)/2;
     temp=S*(S-a)*(S-b)*(S-c);
     at=sqrt(temp);
     printf("Area of triangle is %3.2lf",at);

     getch();
}


Out Put




Share:

List the various types of loop available in C and explain any one with the syntax and suitable example.

 List the various types of loop available in C and explain any one with the syntax and suitable example.



Index

1. What is Loop

2. Various Type of Loop

3. Example of Loop

Ans: 

What is Loop

Loops:-Loops are the statement used to execute a sequence of instruction repeatedly. 

Various Type of Loop

There are three types of loop statements in C:
1.    for loop
2.    while loop
3.    do while loop

 

(1)    for loop:- for loop is used to execute statement multiple times .

            Syntax of for loop:-

            for(initialization ; condition ; increment/decrement){

                                    //body of loop

                        }

 

            Example:-

#include <stdio.h>

int main()

{

for(    int i = 5; i<10;i++)

 {

printf("%d\n",i);

    }

    return 0;

}

 

           

(2)    while loop:-The while loop is a control flow statement which is used to execute the statement repeatedly till the condition statement is true.

 

Syntax for while loop:-

while (boolean condition)

{

   loop statements...

}

 

Example:-

#include <stdio.h>

int main()

{

    int i = 5;

      while (i< 10) {

printf("%d\n",i);

i++;

    }

    return 0;

}

 

(3)    do-while:- Do while loop is similar to while loop with a difference that do-while loop execute the state then after that is check the condition.

Syntax for do-while loop:-

do

{

    statements..

}

while (condition);

 

Example:-

#include <stdio.h>

int main()

{

    int i = 5;

      do {

printf("%d\n",i);

i++;

    } while (i< 10)

    return 0;

}

Share:

What do you mean by an Array || How to declare and initialize 1-D array in C

What do you mean by an Array ? How to declare and initialize 1-D array in C? What is a limitation of an array? Write a program to perform the addition of 3x3 matrices using an array.



Index

1. What do you mean by an Array 

2. How to declare and initialize 1-D array in C

3. What is a limitation of an array

4. Write a program to perform the addition of 3x3 matrices using an array

What do you mean by an Array 

Array:- An array is a non primitive linear type data structure. An array is basically a collection of similar type of data structure which aims to bind similar data together. It is a simple data structure where data items are accessed using indexing.

How to declare and initialize 1-D array in C

Syntax for declaration of array :-

 

                        1D array:-        data_type[no_of_element];

                        2D array:-        data_type[no_of_row][no_of_column];

                        ND array:-        datatype[number]…….n times;

 

Iinitialization of array :-

                        int arr[5] = {1,4,6,3,8};

 What is a limitation of an array

limitation of array:-

  1. Their must be a prior knowledge of number of element to be stored.
  2. An array is a static structure, means the size of the array can not be modified after its declaration.
  3. Insertion and deletion of element is complex in an array.
  4. Allocating memory more than required causes wastage of memory.

 program to perform the addition of 3x3 matrices using an array

A program to perform the addition of 3x3 matrices using an array:-

#include<stdio.h>

#include<conio.h>

int main()

{

 int matrixA[3][3],matrixB[3][3],matrixC[3][3];

 int r,c,k;

 for(r=0; r<3; r++)

 {

  for(c=0; c<3; c++)

  {

printf("Enter first matrix : ");

scanf("%d", &matrixA[r][c]);

  }

 }

 for(r=0; r<3; r++)

 {

  for(c=0; c<3; c++)

  {

printf("Enter second matrix : ");

scanf("%d", &matrixB[r][c]);

  }

 }

 for(r=0; r<3; r++)

 {

  for(c=0; c<3; c++)

  {

matrixC[r][c]=0;

    for(k=0; k<3;k++)

matrixC[r][c] = matrixA[r][c] + matrixB[r][c];

  }

 }

printf("\n New addition matrix : \n");

 for(r=0; r<3; r++)

 {

  for(c=0; c<3; c++)

printf(" %d\t",matrixC[r][c]);

printf("\n");

 }

getch();

 return 0;

}

Share:

Translate

Followers

Email Subscription

Enter your email address:

Delivered by FeedBurner

Recent Posts

Theme Support

Need our help to upload or customize this blogger template? Contact me with details about the theme customization you need.