Saturday 5 January 2019

Find Static Variables[c programming examples with output]

C programming examples with output

Find Static Variables
Program

#include<stdio.h>
#include<conio.h>
main()
{
     int c;
     clrscr();
     for(c=1;c<=3;c++)
     stat();
     getch();
     }
     stat()
     {
     static int sv=0;
     sv=sv+1;
     printf("%d",sv);
}

Output
1
2
3

Reverse of a number[c programming examples with output]

C programming examples with output

Reverse of a number
Program

#include<stdio.h>
#include<conio.h>
main()
{
      int n,rev=0;
      printf("Enter a number to rev:\n");
      scanf("%d",&n);
      while(n!=0)
      {
         rev=rev*10;
         rev=rev+n%10;
         n=n/10;
      }
      printf("Reverse of entered number is=%d\n",rev);
      getch();
}

Output:
Enter a number to reverse:
1234
Reverse of entered number is=4321

Find factorial of a number[c programming examples with output]

C programming examples with output

Find factorial of a number
Program

#include<stdio.h>
#include<conio.h>
main()
{
      int a,b,c;
      clrscr();
      printf("Enter any number  :");
      scanf("%d",&a);
      c=a;
      b=1;
      while(c>0)
     {
          b=b*c;
          c-;
     }
     printf("Factorial of %d  :  %d",a,b);
     getch();
}

Output
Enter any number:6
Factorial of 6:720

Friday 4 January 2019

Electricity Bill[c programming examples with output]

C programming examples with output

Electricity Bill
Program

#include<stdio.h>
#include<conio.h>
main()
{
        int cno,pmr,cmr,cu;
        float total;
        char sec;
        char cname[10];
        clrscr();
        printf("Enter the sector                :");
        scanf("%c",&sec);
        printf("Enter customer name        :");
        scanf("%s",cname);
        printf("Enter customer number     :");
        scanf("%d",&cno);
        printf("Enter the previous units     :");
        scanf("%d",&pmr);
        printf("Enter the current units       :");
        scanf("%d",&cmr);
        cu=cmr-pmr;
        if(sec=='a')
          {
            if(cu>300)
            total=cu*2.00;
                 if(cu>200 && cu<=300)
                 total=cu*1.50;
                       if(cu>100 && cu<=200)
                       total=cu*1.00;
                             if(cu<=100)
                             total=cu*0.50;
          }
          if(sec=='i')
          {
              if(cu>300)
              total=cu*4.00;
                     if(cu>200 && cu<=300)
                     total=cu*3.00;
                             if(cu>100 && cu<=200)
                             total=cu*2.00;
                                      if(cu<=100)
                                      total=cu*1.00;
}
if(sec=='d')
   {
          if(cu>300)
          total=cu*2.00;
                  if(cu>200 && cu<=300)
                  total=cu*1.50;
                         if(cu>100 && cu<=200)
                         total=cu*1.00;
                                if(cu<=100)
                                total=cu*0.50;
  }
           printf("\nCustomer name     :  %s",cname);
           printf('\nCustomer number   :  %d",cno);
           prinf("\nPrevious units         :  %d",pmr);
           printf('\nCurrent units           :  %d",cmr);
           printf("\nCategory                 :  %c",sec);
           printf("\nConsumed units      :  %d",cu);
           printf("\nElectric bill             :  %f",total);
           getch();
}

Output
Enter the sector                 :i
Enter customer name        :Ram
Enter customer number    :1234
Enter the privious units     :567
Enter the current units       :890
Customer name                 :Ram
Customer number             :1234
Previous units                   :567
Current units                     :890
Category                           :i
Consumed units                :323