Wednesday, August 10, 2011

C Program find Positive Negative with Switch Case Without Conditional Operator


write a program in c to check whether the given num is Positive or negative using switch case without conditional operator

 ‎#include<stdio.h>
#include<conio.h>
void main(void)
{
char num;
clrscr();
printf("Enter a number +ve or -ve : ");
scanf("%c",&num);
switch(num)
{
case '-':
printf("Negative number");
break;
default:
printf("Positive number");
}
getch();
}

Example of Using Strings in C


Example of Using Strings in C

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

void main()
{
char *a;
printf("Enter your name=");
gets(a);
printf("%s",a);
getch();

ATM programing


ATM C programing language Program code

 ‎/*Note Pin code is 1234*/
#include<stdio.h>
#include<conio.h>

void main(void)
{ unsigned long amount=1000,deposit,withdr​aw;
int choice,pin=0,k=0;
char another='y';

while(pin!=1234)
{ clrscr();
gotoxy(30,25);
printf("Enter pin:");
scanf("%d",&pin);
}
clrscr();
do
{

printf("********Welcome to ATM Service**************\n");
printf("1. Check Balance\n");
printf("2. Withdraw Cash\n");
printf("3. Deposit Cash\n");
printf("4. Quit\n");
printf("******************​**************************​*\n\n");
printf("Enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nYour Balance is Rs : %lu ",amount);
break;
case 2:
printf("\nEnter the amount to withdraw: ");
scanf("%lu",&withdraw);
if(withdraw%100!=0)
{
printf("\nPlease enter

amount in multiples of 100");
}else if(withdraw>(amount-500))
{

printf("\nInsufficient Funds");
}else
{

amount=amount-withdraw;

printf("\n\nPlease collect cash");

printf("\nYour balance is %lu",amount);
}
break;
case 3:
printf("\nEnter amount to deposit");
scanf("%lu",&deposit);
amount=amount+deposit;
printf("Your balance is %lu",amount);
break;
case 4:
printf("\nThank you for using ATM");
break;
default:
printf("\nInvalid Choice");
}
printf("\n\n\nDo you want another transaction?(y/n): ");
fflush(stdin);
scanf("%c",&another);
if(another=='n'||another==​'N')
k=1;
}while(!k);
printf("\n\nHave a nice day");
getch();

}

Greatest of two numbers using relational conditional operators

program to find greatest of 2 numbers without using relational and conditional operators

‎#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
int a,b;
clrscr();
printf("Enter a number: ");
scanf("%d",&a);
printf("Enter another number: ");
scanf("%d",&b);
printf("The greatest number is %d",(a+b+abs(a-b))/2);
getch();
}

how 2 find a given number is positive or negative number in C without using relational and conditional operator


‎# include<stdio.h>
# include<conio.h>
# include<math.h>
void main()
{
clrscr();
int p,n;
printf("Enter two no=");
scanf("%d",&p);
switch(n=abs(p)+(-p))
{
case 0:
{
printf("Positive number");
break;
}
default:
{
printf("Negative number");
break;
}
}
getch();
}

find a given number is positive or negative number in C without if statement, relational and conditional operator

# include <math.h>
# include <stdio.h>
# include <conio.h>
void main()
{
clrscr();
int p,n;
printf("Enter two no=");
scanf("%d",&amp;p);
switch(n=abs(p) +(-p))
{
case 0:
{
printf("Positiv e number");
break;
}
default:
{
printf("Negativ e number");
break;
}
}
getch();
}

Facebook Page

we have recently created Facebook Page for free-c-programs.blogspot.com. On this page we will be updating the information and posts about this websites. If you are on facebook, you can like this page just by clicking on LIKE button on the right box of this website, which displays on every page of this site. C Programming Facebook Page will provide you Material about Progarmming Language and other related websites

Join us on Facebook Now :)