Friday, May 5, 2017

Algorithm to find the factorial of a number entered by user.

Step 1: Start
Step 2: Declare variables n,factorial and i.
Step 3: Initialize variables
          factorial←1
          i←1
Step 4: Read value of n
Step 5: Repeat the steps until i=n
     5.1: factorial←factorial*i
     5.2: i←i+1
Step 6: Display factorial
Step 7: Stop

C program to add two numbers


#include<stdio.h>

int main()
{
   int a, b, c;

   printf("Enter two numbers to add\n");
   scanf("%d%d",&a,&b);

   c = a + b;

   printf("Sum of entered numbers = %d\n",c);

   return 0;
}

C program to calculate power of number.

#include<stdio.h>
#include<conio.h>
int main()
{
 int num,pow,res=1;
 printf("\nEnter number and power : ");
 scanf("%d %d",&num,&pow);
 while(pow>=1)
 {
  res=res*num;
  pow--;
 }
 printf("%d",res);
 return 0;
}

C program to read name and address from user and display it on screen.

#include<stdio.h>
int main()
{
 int name,address;
 printf("Enter your name:");
 scanf("%s", &name);
 printf("Enter your address:");
 scanf("%s", &address);
 printf("Your name is: %s. \n",name);
 printf("Your address is: %s", address);
 return 0;
}


Output of program


Enter your name:Laxman Poudel
Enter your address:Butwal
Your name is:Laxman Poudel.
Your address is:Butwal

Algorithm to find the Fibonacci series till term≤1000.

Step 1: Start
Step 2: Declare variables first_term,second_term and temp.
Step 3: Initialize variables first_term←0 second_term←1
Step 4: Display first_term and second_term
Step 5: Repeat the steps until second_term≤1000
     5.1: temp←second_term
     5.2: second_term←second_term+first term
     5.3: first_term←temp
     5.4: Display second_term
Step 6: Stop

Wednesday, April 12, 2017

C Program to find the simple interest

#include<stdio.h>

int main() 
{
   int amount, rate, time, si;

   printf("\nEnter Principal Amount : ");
   scanf("%d", &amount);

   printf("\nEnter Rate of Interest : ");
   scanf("%d", &rate);

   printf("\nEnter Period of Time   : ");
   scanf("%d", &time);

   si = (amount * rate * time) / 100;
   printf("\nSimple Interest : %d", si);

   return(0);
}

C program to calculate power of number.

#include<stdio.h>
#include<conio.h>
int main()
{
 int num,pow,res=1;
 printf("\nEnter number and power : ");
 scanf("%d %d",&num,&pow);
 while(pow>=1)
 {
  res=res*num;
  pow--;
 }
 printf("%d",res);
 return 0;
}