Tuesday, 4 December 2012

strcmp | How to check password in C with Break Statement and while

strcmp  |  How to check password in C with Break Statement and while

I don't have so much idea about its execution but at last its using strcmp to compare
original password and entered password by using f7 key you can get its idea .

#include<stdio.h> //initializing header files
#include<conio.h>
void main()
{
void pass();  // function name pass
clrscr();
pass();
printf("\n\nNow you can proceed...........\n");
getch();
}
void pass()
{
char ar[30],ch; //
int i=0;
printf("\n\nEnter password\n");
while(1)
{
ch=getch();
if(ch==13)
break;
else
{
ar[i]=ch;
i++;
printf("*");
}
}
ar[i]='\0';
if(strcmp(ar,"yourvalue")==0)
return;
else
{
printf("Invalid password try again\nPress any key to continu\n");
getch();
pass();
}
}

c program for positive (+ve)and negative(-ve) number | comments with source code example

c program for positive (+ve)and negative(-ve) number | comments with source code example

Positive number means number which is not negetive means number greater than 0 or equal to zero.
let's take example.
9 - 8=1
After subtracting 8 from 9 we will get out put =1 that is positive.
but if i will subtract 9 from 8 like 8 - 9= -1.
i will get out put like -1.
go to start -> run  -> calc .
it will open calci and then  you can calculate.or do any kind of calculation.so , in this program i am going to show  How to find out positive and negative number.
with comments in c program with source code.at last output.

#include<stdio.h>    //header files//
#include<conio.h>   //for clrscr//
main()
{                           //main start//
int user_number;       //declaration//
clrscr();                    //clear the screen//
printf("enter any number"); //taken number from user//
scanf("%d",&number);
//condition//

if(user_number>0)  //if user number is Greater than zero//
{
printf("\n the given number  is positive");
}

if(user_number<0) //if user number is Less than zero//
{
printf("\n the given number  is negetive");
}
getch();
}               //Let see the out-put
output is
enter any number 68
number  is positive

enter any number -56
a is negative

Tuesday, 20 November 2012

C program code for reverse number using function with while loop

 C program code for reverse number using function with  while loop

how to write code to reverse given number in c program using function with comments
#include<stdio.h>  //including header files
#include<conio.h>
long int reverse(long int); // declaring function with parameter
void main()    // start main
{
 long int n;
 clrscr();
 printf("enter the value \n"); // asking for enter the value
 scanf("%ld",&n); // taking value from user
 printf("result=%ld",reverse(n));  //calling function
 getch();
 }
long int reverse(long int a)  // intialization of function
{
 int r;
 long int s=0;
 while (a != 0)  // checking number will not zero
 {
  r=a%10;    
  s=10*(s+r);
  a=a/10;
  reverse(a);  // reversing number
  }
 return (s/10); //returning reversed number
 }
c programming example  for reverse number using function with  while loop

c program factorial number using function.

c program  factorial number  using function.

Take two for loop .first for loop for one to last .
till we want to factorial and second will calculate factorial of each number.
factorial means multiplication of numbers.
example
factorial of 5 is 5*4*3*2*1=120.
so factorial of 5 is 120.
same for 6 is 6*5*4*3*2*1=720.



#include<stdio.h>
#include<conio.h>
long int fact( int*);
void main()
{
  int n;
  clrscr();
  printf("enter the value \n");
  scanf("%d",&n) ;
  printf("result=%ld",fact(&n)) ;
  getch();
  }

 long int fact(int* a)
 {
 long int f=1,sum=0;  //initialization of sum=0 and variable f =1.
 int i,j;
 for(i=1;i<=*a;i++) //execution of for loop
 {
  for(j=1;j<=i;j++) // second for loop
  {
  f=f*i;
  }
  f=i/f;
  sum=sum+f;
  }
  return sum; // will return the factorial of given number.
  }


programming examples for  factorial number  using function

how to draw concentric circles with help of while loop

how to draw concentric circles with help of while loop

concentric  circles which share same axis ,center and origin.
so sphere and disks are concentric circle we can assume.

#include<graphics.h> //graphic shows header file for design in c language.

main()
{
    int gd=DETECT,gm;
    int n,x=10;
    initgraph(&gd,&gm," ");
    printf("How many concentric circles do you want?");//asking for number of circle want to draw.
    scanf("%d",&n);
    while(n!=0)
    {
    circle(240,150,x);
    setcolor(GREEN);// setting color as green.
    x+=10;
    n--;
    }
    getch(); // end of main
    closegraph();
}
programming examples for concentric circles