Q. Can you give me example for If else statement in C Program under Linux or TC?
A. C follows universal syntax for if..else. You can use any complier GNU Linux gcc or UNIX or old good TC.
if..else syntax
General if..else syntax is as follows:
if ( condition ) {
expr_set1;
}
else {
expr_set2;
}If given condition is TRUE, expr_set1 will get executed.
If given condition is FALSE (not TRUE), expr_set2 will get executed.
if..else example
Following example will find out large number from given input:
#include<stdio.h>
int main(){
int x,y;
printf("Enter value for x :");
scanf("%d",&x);
printf("Enter value for y :");
scanf("%d",&y);
if ( x > y ){
printf("X is large number - %d\n",x);
}
else{
printf("Y is large number - %d\n",y);
}
return 0;
}
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 172 comments… read them below or add one }
i need more information about “if else”
#include
main()
{
int grade;
char student[25],section[25];
clrscr();
printf(“Enter the name of a student: “);
scanf(“%s”, &student);
printf(“Enter the section of a student: “);
scanf(“%s”, §ion);
printf(“Enter the grade of a student: “);
scanf(“%d”, &grade);
if(grade>75)
printf(“PASSED”);
else
print(“FAILED”);
getch();
}
friend your “scanf(“%s”, &student); ” is not correct
the correct is “scanf(“%s”, student); ” thank you.
yes,it should be no & for character string,which means for name. only the character we must include the sign & for the scanf
yes mira i also mean the same
require more explanation
and examples
if statements is a conditional statements that executes on a particular condition
the syntax is
if (true) /* Here true means if(12>10) ,this is true so it will execute. */
{
execute this code
}
else
{
else execute this code
}
i need the answer for small and greatest number in 10 numbers
why we use return 0 in the last of program
I need more if else program.i have simple problem.i don’t know your wbsite is active or not.next time i give a problem please solve it.
I need more program about if else
#include
#include
main()
{
int age;
clrscr();
printf(“Enter the age:”);
scanf(“%d”, &a);
if(a<18)
printf("can't vote");
else
printf("can vote");
}
its wrong miss meera actually, wat u declared is age, and wat u using in (if statement) is a thats y its an error program
#include
#include
void main()
{
int n;
clrscr();
printf(“enter the number:”);
scanf(“%d”,&n);
if (n%2==0)
printf(“the number is even”);
else
printf(“the number is odd”);
getch;
}
i need a example w/ no limitation..
there is error about voat.it gives only cannot voat
#include
main();
{
int marks;
scanf(“%d”,&marks);
if(marks>35)
printf(“Pass”);
else
printf(“Fail”);
}
PROGRAM To find whether a given year is leap or not
main()
{
int y,r1,r2;
printf(“Enter a year”);
scanf(“%d”,&y);
r1=y%4;
if (r1 = = 0)
{
r2=y%100;
if(r2 = = 0)
printf(“The given year is not a leap year”);
else
printf(“The given year is a leap year”);
}
else
printf(“The given year is not a leap year”);
}
what do u mean by “y”,”r1″,”r2″ integer there?thnks!
why we use y%4.show me answer
y%4
that means which value is store in y that is divided by 4
% is a modular
y%4 does not store the value in y the correct process is y=y%4
the year divided by 4, get remainder zero ,is leap year.
void main()
{
int num,grenum;
grenum=10;
printf(“Enter the number: “);
scanf(“%d”,&num);
if(num>gernum)
{
printf(“The number is Greater”);
}
else{
printf(“The number is smaller”);
}
}
can you convert this to java program?
I just study programming .
hello all..exiting ang programming nuh?haha
how to analyze the problem to make c program?tnx
hi i am a n IT student. i just want to ask if you could pls give me some simple problems regarding if else , if else if else, and i/o. and also those more complicated ones. thanks.
Super Example For If Statement
#include
main()
{
int age;
Printf(“Age selection for Security”);
scanf(“%d”,&age);
if(age<50)
printf("Selected");
else
pritnf("Age excess-Sorry try Another place");
}
void main()
{
int i,n;
printf(“Enter the level\n”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
if(i%2==0)
{
printf("even number=%d",i);
}
else
{
printf("odd number=%d",i);
}
}
}
i’m excited to try this program
i need to create program right now for my project …………….help me …………………hehehe using IF ELSE STATEMENT
Give me another example of IF ELSE STATEMENT
void main()
{
int a;
printf(“enter the a value\n”);
scanf(“%d”,&a);
if(a>0)
printf(“a is positive”);
else
printf(“a is negative”);
}
can you help me to write this home work in C programs
*wirte the programsin C about if else
*the program should ask the user to enter the total marks out of 100, and then display the letter grade on the screen
*Grade Rules:
75 and above=”A”grade
60-74=”B”grade
50-59=”c”grade
40-49=”D”grade
Below 40=”Fail”
thanks .
please send it to my Email bayan321@live.com
Your homework is very easy just use the
if(user>=75)
printf(“A”);
else if(user>=60 && user<=74)
printf("B");
and so on.
did you manage to get the answer?
did anyone mailed you?
thanks
sujesha
void main()
{
float mark;
clrscr();
printf(“Enter the total mark out of 100″);
scanf(“%f”,&mark);
if(mark<==75)
{
print{"Student has secured A Grade ";
}
else
{
.
.
.
.
.
.
getch();
}
thank u..
i need some help guys
i am making a function oriented program and i used if else statement, i know that my statement is right but there is only 1 error and it says misplaced else…..
how can i fix that?
pls help me….
plss notify me on my email
thanks
you should misplace the curly braces { }. the syntax is
if (condition) {
statement 1
}
else {
statement 2
}
Hello
make sure you use the proper braces before and after else statement.
hey else ya if ke baad semi colon ya brackat hoga isliye yeh erro aa rahi hai …………..
for example
else();
if()
so if and else use without any syntax…..
for example
if(condition)
{
statements(s)
}
else
{
statament(s)
}
ok byyyyyyyyyyyeeeeeeeeeeeeeeeeeeee
can you give more examples :-)
Thanks I love you!!
pls. give me a program example of official receipt of sm using if else statement pls. we need it badly…pls…thanx
why can’t I place another “if statement” inside and “if statement”?
using visual basic net i have to write a program using if-else statement based on the following condition the grdes of the students
0-49 D
50-55 C
56-60 C+
61-70 B
71-75 B+
76-85 A
86-100 A+
The program should repeat itself unless the user enters a negative value to terminate the program
can you give me the def of if family statements
include
int main(){
int x,y;
printf(“Enter value for x :”);
scanf(“%d”,&x);
printf(“Enter value for y :”);
scanf(“%d”,&y);
if ( x > y ){
printf(“x is large number – %d\n”,x);
}
else{
printf(“y is large number – %d\n”,y);
}
return 0;
}
Use indentations ur prblm wl be solved
PLEASE HELP ME!!!!
Can you answer the code of this?
The output is:
Enter the first number:
Enter the second number:
Enter the third number:
The smallest number is:
The middle number is:
The largest number is:
#include
main()
{
int x,y,z;
clrscr();
printf(“Enter the first number:”);
scanf(“%d”,&x);
printf(“Enter the second number:”);
scanf(“%d”,&y);
printf(“Enter the third number:”);
scanf(“%d”,&z);
z=x+y+z;
y=x+y+z;
x=x+y+z;
printf(“The smallest number is:%d\n”,z);
printf(“The middle number is:%d\n”,y);
printf(“The largest number is:%d\n”,x);
getch();
return 0;
}
can you make a program in this question?
plss reply at my email address, asap!!!
Objective:To learn how to write a C++ program using switch and do-while loop as applied to a simple airline application.
Procedure:
Write a program that will validate the status code so that only values from 0 to 3 will be accepted.If an invalid status code is entered, display the message “Invalid Status” and repeatedly accept a status code until a valid value is entered.Repeatedly accept passenger data prompting for “More Entries? (Y/N):” each time a set of data is entered.Terminate processing when response to this prompt is ‘N’.
Note: for string values you need to use strcpy function to assign the value entered to a character array variable (refer to your manual).
Name: XXXXXXXXXXXXXXXXX
Status:XChecked-in
Fare:9,999.99
Specifications:
1.The name of student and exercise no. should appear on screen.
2.Segregate input, process, validation and output statements by introducing void functions
3.Maintain the same display format as follows taking consideration of the error message and the “More Entries” prompt.
Name: XXXXXXXXXXXXXXXXX
Status :XBoarded
Fare:9999.99
More Entries? (Y/N):
4.Use the switch statement to display the corresponding descriptive status.
Statusdescription
0On-Schedule
1 Checked-In
2 Boarded
3 Arrived
Thanx for help my study
Make a C program that will accept any integers from 1-12 and displays equivalent month, Example if 3 “March”.
you could try using either switch case or nested if for that program
#include
main()
{
int month;
printf(“\n Enter Number:”);
scanf(“%d”,&month);
switch(month){
case 1: printf(“January”);
break;
case 2: printf(“Febuary”);
break;
case 3:… and so on up to case 12..
default: printf(“number selected is invalid”);
}
}
i need more explanation of if-esle statement also example….
i want to do a menu using if else,but after i try the error is occur.the error say that i using illege if else..wat is the problem that i face ,n how can i solve tis problem
how to find square root of a number by using if else in c program?
can you make a program that converts the value of binary to decimal, binary to-octal binary-hexa and decimal-binary, decimal-octal, decimal-hexa, and octal-decimal,octal-binary,octal-hexa, and hexa-binary,hexa-decimal,.hexa-octal;
your prompt reply is highly appreciated. thank you in advance.!
god bless..
-SAMPLE “IF ELSE” PROGRAM-
#include
#include
int main(){
int grade;
clrscr();
printf(“Enter Grade:\n”);
scanf(“%d”, &grade);
if((grade>=80)&&(grade=75)&&(grade<=79))
printf("Nice");
else
printf("Poor");
getche();
return 0;
}
can you make a program in this output?
output
MODE OF PAYMENT
[1] CASH 10% DISCOUNT
[2] TWO-INSTALLMENT 5% INTEREST
[3] THREE-INSTALLMENT 10% INTEREST
ENTER YOUR TUITION FEE: 20,000
CHOOSE MODE OF PAYMENT: 1
THE AMOUNT OF PAYMENT:18,000
this is the output plsss. help me
can any one solve this:
write a c program tht accept n integear from the user and pass it to the function that print the crossponding day 1=saturday
2=sunday
3=monday
4=tuesday
5=wednesday
6=thursday
7=friday
#include
#include
void main()
{
int no_day;
clrscr();
printf(“enter the number of day \n”);
scanf(“%d”,&no_day);
switch(no_day)
{
case 2 :
printf(“sunday”);
break;
case 3 :
printf(“monday”);
break;
case 4 :
printf(“tuesday”);
break;
case 5 :
printf(“wednesday”);
break;
case 6 :
printf(“thursday”);
break;
case 7 :
printf(“friday”);
break;
default :
printf(“no match “);
}
getch();
}
void main(){
int i;
switch(i){
case 1:
Printf(”monday”);
case 2:
Printf(”tuesday”);
case 3:
Printf(”wednesday”);
Case 4:
Printf(”thursday”);
.
.
.
Case 7:
Printf(”sunday”);
Default:
Printf(”enter appropriate number”);
}
}
can you help me with this…
ADDI, is one of the courier company that provide express service in delivering goods to customers. The tariff are based on total weight and delivery destination. Table below shows the pricelist.
Table 1 : Weight
Total Weight Price per kg
1st kilogram 15.00
The next 4kg ( 2-5kg) 13.00
The next 20kg (6-25 kg) RM 11.00
More than 25 kg RM 10.00
Table 2 : Destination
Destination Rate
Within a state
i. 1-25km
i. RM 5
ii. More than 25 km ii. RM 15
Domestic RM 30
For express delivery (within 1 day delivery), extra RM 25.00 is add.
You are required to write a program that will help customer to calculate the tariff based on information given. Your program shall display:
• Type of goods – documents or parcel
• Quantity
• Total weight
• Destination
• And delivery type – normal or express
• Total price to be paid
please give me a code using array and function
i need more informations of c programs.
can anyone help me to convert binary to octal by using for loop and bit wise operator.
what does bit wise (n>>i &7) mean and in last for loop what does i -= 3 mean.how is it related to convert octal.can anyone please help me this,
can you help me in making calc with frem
i want more in formation about the if else statement.
i want to know more abt if else
#include
int main(){
int x,y;
printf(“Enter value for x :”);
scanf(“%d”,&x);
printf(“Enter value for y :”);
scanf(“%d”,&y);
if ( x > y ){
printf(“x is large number – %d\n”,x);
}
else{
printf(“y is large number – %d\n”,y);
}
return 0;
}
even though compiler says “succes” .i can’t run the program it says elseif statement error
can u help me to get the c code of this….
enter the first no:20
enter the second no:30
selection operation:+,-,/,%
can you give me a program for votation?? dat would also count the votes and declare who will win !!! please??? i’m begging you guys..!!!
Kindly please help me with this:
Write a program that ask the user to input item name, item unit per price and item quantity. Determine the following:
Range(Quantity) Discount
0-50 0%
51-90 1%
90-100 2%
101-500 3%
501-1000 5%
1001-5000 7%
5801-above 10%
Can you help me figure out this problem?
This game is like the traditional “bato-bato pick” we Filipinos play. In this game, the user will select among “BATO”, “PAPEL”, and “GUNTING”. The computer will randomly select it’s pick. The game will be played for 5 rounds. The program will display the winner every after round and the player with the most win after 5 rounds will be declared as the winner. In case of a tie provide another round until the tie is broken.
Kindly help me. Using C Language programming only, Using if-else statement without the use of loop or jump. Thanks
1 scan four values from user and find maximum number from four numbers.
2.read any character from user and check whether that character is vowel or not . using conditional operator. (a,e,i,o,u are called vowel)
Can you make a c program on this problem please:
-make a c program using “if else statements” where when you enter a month(in small letters), it will display the holidays on that month!
please, email me!
/*Write a c program to accept any character and print their ASCII code.
sol:-
#include
#include
void main()
{
clrscr();
char ch;
printf(“\nEnter any character:-”);
scanf(“%c”,&ch);
printf(“ASCII code=%d”,ch);
getch();
}
i require a c program by using if else statement to print smallest of given four numbers
#include
#include
void main()
{
int a=10,b=20,c=30,d=40;
if (a<b && a<c && a< d)
printf("A is smallest");
else if (b<a &&b<c &&b<d)
printf(" b is smallest );
else if (c <a && c<b && c <d)
printf("c is smallest");
else
printf("D is smallest");
getch()
}
i require a c program by using if else statement to print smallest of given four numbers
please email me
i want more in formation about the if else statement.
I need help with writing a program that prompts the user to enter two dates and then indicate which date comes earlier on the calendar
Enter first date (mm/dd/yy): 3/6/08
Enter second date (mm/dd/yy): 5/17/07
5/17/07 is earlier than 3/6/08
Your help would be greatly appreciated!!!!!
Reading everything but the original post made me feel dumber. To everyone:
1) Learn how to spell. and when and when not to capitalize
2) Actually learn something about C before coming here.
//program for bell sound
#include
#include
void main()
{
clrscr();
printf(“\a wellcome wwww \ a”);
getch();
}
good and interesting
can you give me more definitions about if-else statement plsss..tnx a lot
can you make a program in this output?
output
MODE OF PAYMENT
[1] CASH 10% DISCOUNT
[2] TWO-INSTALLMENT 5% INTEREST
[3] THREE-INSTALLMENT 10% INTEREST
ENTER YOUR TUITION FEE: 20,000
CHOOSE MODE OF PAYMENT: 1
THE AMOUNT OF PAYMENT:18,000
this is the output plsss. help me
write a c program that will get 4 integers and will print out the maximum integer…can anyone solve this?
i have some problem’s in if else statements or give me suggestion how i read about it
Help me plss i dont run. idont make. pls explore . . .
1. The proper divisors of a positive integer n are those integers, excluding n itself,
that
divide n exactly. For example, the proper divisors of 12 are 1, 2, 3, 4 and 6.
Write a program that inputs a positive integer and outputs its proper divisors.
Sample run :
Input: 8
Output: 1 2 4
2. A program that accepts a set of integers and displays the number of positive and negative
numbers. The program stops when the user enters 0 for the integer value.
2. Write a program that reads the marks of a student, determine and prints the equivalent grade, based on the following:
Marks Range Grade
< 45 E
45 <= Marks < 60 D
60 <= Marks < 75 C
75 <= Marks = 90 A
i got do.but there got some error that i can’t find.please help me.
#include
void main()
{
int mark;
char grade;
printf(“Enter your mark:”);
scanf(“%f”,&mark);
if(mark<45)
grade='E';
else if(mark<=45 && mark<60)
grade='D';
else if (mark<=60 && mark<75)
grade='C';
else if(mark<=75 && mark=90);
grade=’A';
printf(“Your grade is %c\n”,grade);
}
Please give me answer for this question
Suppose a company decides to raise the salaries of its employees according to the following table:
employee_status years_of_service percent_raise
Full-time Less than 5 years 4.0
Full-time 5 years or more 5.0
Part-time Less than 5 years 2.5
Part-time 5 years or more 3.0
If employee_status value is ‘F’, the employee is Full-time; if it is ‘P’, he or she is part-time. Using any selection control structure of your choice, write a program that computes the new salary of an employee given his or her employee_status, years_of_service and salary by the users.
Write a program that prompts the user to input an integer between 0 and 25. If user enters 0 then Display A, if user enters 1 then Display B, if user enter 2 then Display C and so On…
can someone solve this problem for me .
~ leave a comment “//” of their use and function..
[1]van arrives
[2]passenger arrives
[3]passenger boards van
[4]van leaves
each van has the following properties: plate number, driver,passenger, limit
let letters represent passenger vans and numbers represent passenger
flow of van and passenger is as follows
raymark: IF event 1 happens, then a van arrives at the terminal..
starting with label A
there can only be one passenger van at the terminal
at a time
hence
if event 1 happens while there is still a van at the terminal, . message saying “terminal is full”
should be displayed. the next van that arrives at the terminal should be labeled as b and so on
if event 2 happens, a passenger arrives at the terminal, starting with label 1, if there is a van at the terminal, then the passenger boards the van automatically(event3). otherwise, the passenger waits in a queue. once a van arrives the passenger un the queue will automatically load the van.
a van automatically leaves the terminal(event4) if the number of a passenger who have boarded is equal to the passenger limit of the van
the foolowing information mus be displayed at all times: current van label and passenger list.
you are to write an iterative, menu driven JAVA APPLICATION that simulates the van at ATC
the following implementation details are req: functions use of control structures – selection and control and use of variable
( free to organize your menu choices as long as the feature described above . )
Your help would be greatly appreciated!!!!!
send to my email..
follow up ! using DEV c++ compiler …
Write a program in which user enters the integer value and your program returns its binary equivalent. can any body help me with it?
can u just tell me, wat condition shuld be placed inside for loop
if( )
{
printf(“abcd”);
else
printf(“acdb”)
}
it should give output as
abcd
acdb
or
acdb
abcd
pls can u just tell me wat condition should be given inside if loop..
help me please. I need to make a program entering someone’s birthday and the current date today and it will identify your age. How??
thankz a lot
/*Create a C++ Program that will input
two (2) values and will output its:
-> sum -> exponent product
-> difference -> square root of the first value
-> product -> square root of the second value
-> quotient -> remainder/modulo quotient
-> integer quotient */
#include
#include
using namespace std;
int main()
{
double Number1,Number2,IntegerQoutient;
double Sum,Difference,Product,Qoutient;
double ExponentProduct,squareroot1,squareroot2,remainder;
cout <<"This is a calculator" << endl;
cout <> Number1;
cout <> Number2;
Sum=Number1+Number2;
Difference=Number1 – Number2;
Product=Number1 * Number2;
Qoutient=Number1 / Number2;
IntegerQoutient=Number1/ Number2;
ExponentProduct=pow(Number1,Number2);
squareroot1=sqrt(Number1);
squareroot2=sqrt(Number2);
remainder=fmod(Number1,Number2);
cout <<"OPERATION:" << endl;
cout < Press 1″ << endl;
cout < Press 2″ << endl;
cout < Press 3″ << endl;
cout < Press 4″ << endl;
cout < Press 5″ << endl;
cout < Press 6″ << endl;
cout < Press 7″ << endl;
cout < Press 8″ << endl;
cout < Press 9″ << endl;
int n;
cout << "Please choose any from the option above " <> n;
if (n==1)
cout <<"Youve chosen Addition, the answer is: "<< Sum << endl;
else if (n==2)
cout <<"Youve chosen Subtraction, the answer is: "<< Difference << endl;
else if (n==3)
cout <<"Youve chosen Multiplication, the answer is: "<< Product << endl;
else if (n==4)
cout <<"Youve chosen Division, the answer is: "<< Qoutient << endl;
else if (n==5)
cout <<"Youve chosen IntegerQoutient, the answer is: "<< IntegerQoutient << endl;
else if (n==6)
cout <<"Youve chosen ExponentProduct, the answer is: "<< ExponentProduct << endl;
else if (n==7)
cout <<"Youve chosen Squareroot of 1st no, the answer is: " << squareroot1 << endl;
else if (n==8)
cout <<"Youve chosen Squareroot of 1st no, the answer is:" << squareroot2 << endl;
else if (n==9)
cout <<"Youve chosen Remainder, the answer is:" << remainder <9
/*Create a C++ Program that will input
two (2) values and will output its:
-> sum -> exponent product
-> difference -> square root of the first value
-> product -> square root of the second value
-> quotient -> remainder/modulo quotient
-> integer quotient */
——— my answer
#include
#include
using namespace std;
int main()
{
double Number1,Number2,IntegerQoutient;
double Sum,Difference,Product,Qoutient;
double ExponentProduct,squareroot1,squareroot2,remainder;
cout <<"This is a calculator" << endl;
cout <> Number1;
cout <> Number2;
Sum=Number1+Number2;
Difference=Number1 – Number2;
Product=Number1 * Number2;
Qoutient=Number1 / Number2;
IntegerQoutient=Number1/ Number2;
ExponentProduct=pow(Number1,Number2);
squareroot1=sqrt(Number1);
squareroot2=sqrt(Number2);
remainder=fmod(Number1,Number2);
cout <<"OPERATION:" << endl;
cout < Press 1″ << endl;
cout < Press 2″ << endl;
cout < Press 3″ << endl;
cout < Press 4″ << endl;
cout < Press 5″ << endl;
cout < Press 6″ << endl;
cout < Press 7″ << endl;
cout < Press 8″ << endl;
cout < Press 9″ << endl;
int n;
cout << "Please choose any from the option above " <> n;
if (n==1)
cout <<"Youve chosen Addition, the answer is: "<< Sum << endl;
else if (n==2)
cout <<"Youve chosen Subtraction, the answer is: "<< Difference << endl;
else if (n==3)
cout <<"Youve chosen Multiplication, the answer is: "<< Product << endl;
else if (n==4)
cout <<"Youve chosen Division, the answer is: "<< Qoutient << endl;
else if (n==5)
cout <<"Youve chosen IntegerQoutient, the answer is: "<< IntegerQoutient << endl;
else if (n==6)
cout <<"Youve chosen ExponentProduct, the answer is: "<< ExponentProduct << endl;
else if (n==7)
cout <<"Youve chosen Squareroot of 1st no, the answer is: " << squareroot1 << endl;
else if (n==8)
cout <<"Youve chosen Squareroot of 1st no, the answer is:" << squareroot2 << endl;
else if (n==9)
cout <<"Youve chosen Remainder, the answer is:" << remainder << endl;
return 0;
}
#include
#include
main()
{
int x,y;
clrscr();
printf(“Enter a value for x and y:”);
scanf(“%d%d”,&x,&y);
if(x>y)
printf(“X is greater”);
else
printf(“Y is greater”);
getch();
}
good
when have exersice about time ?what we do in if else?can u example
Thankyou for post!! If- else statement examples still not enough.
Im not being able to find out what exactly the error is here:
#include
void main()
{
int numsweet;
double cost;
printf(“How many icecream do you want : “);
scanf(“%f, &numsweet”);
cost = 12.10 * numsweet;
if (numsweet > 1000)
{
printf(“The store does not have that much icecream in stock!”);
}
else
{
printf(“You have to pay $%f to the cashier!\n Thankyou!\n”, cost);
}
}
It gives a warning saying says “Possible use of numsweet before definition in funtion main. Plz help! any advice is welcomed.
scanf(“%f, &numsweet”);
change this to :
scanf(“%f”, &numsweet);
Your header file declaration is incomplete #include 2.scanf(“%f”,&numsweet); here you didn’t close the conversion or format string with quotes”".
While reading integer use %d & not %f.
%f is used to read a float value not a integer
#include
void main()
{
int n,rem;
clrscr();
printf(“enter the number”);
scanf(“%d”,&n);
rem=n%2
if(rem==0)
printf(“the number is even”);
else
printf(“the number is odd”);
getch();
}
#include
void main()
{
int a=10;
if(x==10)
{
printf(“pop”);
printf(“rock”);
}
else
printf(“song”);
printf(“romance”);
}
o/p:-pop rock romance
i need you help guys about something, i am trying to use “if and else” commands but it’s not working at all, can someone tell me what i did wrong ?!!!
#include
main()
{
char name[4] = {”};
char namem[5] = {”};
printf(“What is your name ?!\n”);
scanf(“%s”, &name);
if(“name==Mark”)
{
printf(“Right, Your name is %s\n\n”, &name);
}
else {
printf(“No, your name is Mark”, &namem);
}
system(“pause”);
}
#include //link section
#include
void main()
{
char name[4]; //local variable declare string type
char namem[5]=”ANIL”; //declare & initialized string
clrscr();
printf(“What is your name ?”);
scanf(“%s”, name); // input any string in run time
if(name==”Mark”) // check condition
{
printf(“Right, Your name is: %s”,name);
}
else
{
printf(“No, your name is Mark %s”, namem);
}
getch();
}
The number 153 has interesting property, it equals to the sum of the cubes of its digit, that is 13+53+33=1+125+27=153. Construct a C Program that reads in a positive three integer number and determine if the number satisfy the property or not. Accordingly, display the number with a message “SATISFY THE PROPERTY” or “DOES NOT SATISFY THE PROPERTY”.
#include
int main()
{
int A,a,B,b,num,T;
printf(“\t Please Enter an Integer you need to check the properties :”);
scanf(“%d”,&num);
A=num%10;
a=num/10;
B=a%10;
b=a/10;
//This is to check the values, in case of confusion//
printf(“A=%d a=%d B=%d b=%d \n”,A,a,B,b);
A=A*A*A;
B=B*B*B;
b=b*b*b;
//This is to check the values, in case of confusion//
printf(“A=%d B=%d b=%d \n”,A,B,b);
T=A+B=b;
if(T==num)
{
printf(“\t SATISFY THE PROPERTY/n”);
}
else
{
printf(“\t DOES NOT SATISFY THE PROPERTY /n”);
}
return 0;
}
Since this is regarding if-else statement you may use this method,but can also reduce the steps by using a for or do-while loop,=)
@hansel
this number 153 is one of the armstrong numbers..
an armstrong number is a number whose sum of the cube of the digits is same as that of the number..
#include
#include
void main()
{
int r,c1,c2,c3,n,t,num;
clrscr();
printf(“\n please enter the 3 digit no.”);
scanf(“%d”,&n);
t=n;
//calculates the cube of last digit
r=n%10;
n=n/10;
c1=r*r*r;
//calculates the cube of middle digit
r=n%10;
n=n/10;
c2=r*r*r;
//calculates the cube of first digit
r=n%10;
n=n/10;
c3=r*r*r;
//sums up the cubes
num=c1+c2+c3;
//checking
if(num==t)
{
printf(“\n%d Satisfies the property”,t);
}
else
{
printf(“\n%d doesnot Satisfies the property”,t);
}
getch();
}
Plss. .help me about this problem. . . .
i want the program to fing greatest among 4 numbers using nested if else ladder
Please help me guys!!!!!!!!!!!!!
I need a program for the sales and inventory system…….ASAP!!!!!!!!!!!
if ever who have a knowledge about the said system please email me at my yahoo account….. annarah_aquipan@yahoo.com
“May God will pay back you for your kindness”……..
Thank you so much!!!!!!!!!!!
pls help me
pls create a program that will accept 5 integers and display the lowest integer
pls use nested if for c++/turbo c
thanks..
pls create a program that will accept 5 integers and display the highest and the lowest number
any conditional statement in c++/turbo c
thanks..
can
some one please help me on my task, i need to write a program that can read 10 integer and then display the:
>biggest number
>smallest number
>total
>average
–>> i badly need the answer regarding this program, can you help me:))
Write a program that complete the users prompt a services of numbers the program must be determine the odd and even number.. prompt by the users ; also sum the odd and even numbers.
Nice to see this site.
am learning c language from this cyberciti.biz web site. its really good to learn c for freshers.
write a program that inputs movie and displays his movie according ti following character ;
s sorrow movie
r romentic movie
a action movie
s scientific movie
f funny movie
//trying first check this program n plz send comment in cool_gtm2005@yahoo.com
void main()
{
char m1[20],m2[20],m3[20],m4[20],m5[20];
char ch;
printf(“Enter the five different movies\n\n”);
scanf(“1 %2s \n %2s \n %2s \n %2s \n %2s”, &m1,&m2,&m3, &m4, &m5);
clrscr();
printf(“enter the choice( S,R,A,s,F) TO GET MOVIES”);
scanf(“%c”,&ch);
if(ch==’S')
printf( ” ur selection is %s”,m1);
eise if (ch==’R')
printf(“ur selection is %s”,m2);
else if ( ch==’A')
printf(“ur selection is %s”,m3);
else if (ch==’s')
printf(” ur selection is %s”,m4);
else
printf(” ur selection is %s”,m5)
getch();
}
what does ch means? i dk, sorry explain.
can anyone say me y do v use == instead =
== is use for if conditions while = is use for assigning a value. for example, if(a==1) and int a=1.
I want to make a program to find out largest and smallest numbers out of 5 numbers using only 10 if statements and 7 printf statements……is there any one who can solve it…please let make it solve quickly its assignment……!!!!
// im trying coo gtm less than 10 if state
void main()
{
int num1,num2,num3,num4,num5,great;
if (num1>num2 && num>num3 && num1>num4 && num1>num5)
great=num1;
else if (num2>num1 && num2 >num3 && num2 >num4 && num2> num5)
great=num2;
else if (num3>num1 && num3 >num2 && num3 >num4 && num3 > num5)
great =num3;
else if (num4>num1 && num4 >num2 && num4 >num3 && num4>num5)
great=num4;
else
grate=num5;
/* same opposite to smallest number*/
printf( “the greatest number is %d”, great);
getch();
}
i want to make a program that will ask the user, how much will be the cost in playing in the computer shop per minute. the program will calculate the cost based on the given formula.
1.) 1 peso every 4mins.
cost * mins = total payment
2.) cost * sec. = total payment
sec. =.25
hi!! i need the answer for this program please. :):)
Write A Program To Accept The Marks Of Five Subjects And Find The Total And Percentage.
Description :-
If Value Of Any Of Five Subjects Is Negative Or Zero Or 100 An Appropriate Error Is To Be Displayed On The Screen And Program Should Terminate.
If(“condition”)
printf(“Hello”);
else
printf(“World”);
What should be the “condition” if the output is “HelloWorld”.
condition means….num==num2 or num!=num2 like this.but you just use
if(condition) but you didn’t give any condition.
hi i need heip from u in this program and my question is
write a program that perform all basic operation of calculator.?
these re options
1) add, sub. multiply, divide
2) using oject and class of iostream and ostream
# long as data type .
plz send me thiz program tomorrow itz my assignment and i ll be very grate ful to u for thiz favour thnkz
I want to print like This In C++ and C
######
#####
####
###
##
#
Thanks
#include
void main()
{
char title[]=”SUBHAS CHANDRA BOSE”;
for(int i=0; title[i];i++)
cout<<"\n"<<(title+i);
}
please, help me task ,
write a c program input any number b/w 1 to 12 and print month name according to input number.(using if else statement)
pls help write a program in c-language. the integral of (2t^2 +3t +1) the limit is from 0 to 4.using the trapezoidal rule
include
main()
{
int m;
cout<>m;
if(m==0)cout<<"Jan";
else if(m==o)cout<<"Feb";
else if(m==o)cout<<"Mar";
else if(m==o)cout<<"Apr";
else if(m==o)cout<<"May";
else if(m==o)cout<<"June";
else if(m==o)cout<<"July";
else if(m==o)cout<<"Aug";
else if(m==o)cout<<"Sept";
else if(m==o)cout<<"Oct";
else if(m==o)cout<<"Nov";
else if(m==o)cout<<"Dec";
else cout<<"Wrong entry";
getch();}
so nice answers are provide and sharing
void main()
{
int i,j;
clrscr();
for(i=1;i=i;j–)
printf(“#”,j);
printf(“\n”);
}
getch();
}
#include
#include
void main()
{
int x;
printf(“enter any number between 1 to 12″);
scanf(“%d”,&x);
if(x==1)
{
printf(“month is jan. %d\n”,x);
}
else if(x==2)
{
printf(“month is feb%d\n”,x);
}
else if(x==3)
{
printf(“month is march .%d\n”,x);
}
else if(x==4)
{
printf(“month is april %d /n”,x);
}
else if……………….
…………………………………….
………………..
………………………
…………………………….
else(x==12)
{
printf(“month is december %d\n”);
}
getch();
}
you have to work with three temperature types: Celsius, Fahrenheit and Kelvin. What we are going to do here, people would come to you to ask to convert temperature. They come with three inputs, the temperature which they want to convert, the type of the temperature and the intended type to convert it. As we are dealing with three types of temperature, we represent them 0, 1 and 2 (Celsius = 0, Fahrenheit = 1 and Kelvin = 2). The temperature is a number (floating point). The output is the temperature in the intended type.
#include
#include
main ()
{
int x,y;
scrclr();
printf(“Enter value for x :”);
scanf(“%d”,&x);
printf(“Enter value for y :”);
scanf(“%d”,&y);
if ( x>y)
{
printf(“X is less-than: %d\n”,x);
}
else{
printf(“Y is greater-than: %d\n”,y);
}
getch();
}
i need while loop examples
#include
main()
{
int i=0;
while(i<10)
{
printf("gud morning");
}
getch();
}
hai, i want a simple program about for loop. may u pls.thanks
the xyz telegram company charges 18.50 for telegram that do not exceed 12 words and 1.50 pesos for every succeeding word.construct a C program that accepts the number of words in a telegram compute and display the charges.
Can anyone clarify on me, on below statement,
if (++time>59)
{
statement1;
}
hai, i want to know about while loop
give the syntax of simple if statement in c
good…but not enough to understand clearly…..
#include
int main()
{
int x,y;
printf(“enter value for x=”);
scanf(“%d”,&x);
printf(“enter value for y=”);
if(x>y){
printf(“x is the greater number=%d\n”,x);
}
else{
printf(“y is the greater number\n”,y);
}
return 0;
}
plz give answer -wap to input number continuslt but only positive number will display input 0 for stop program?
#include
#include
void main()
{
int a;
clrscr();
printf(“enter the any value”);
scanf(“%d”,&a);
if(a==5)
printf(“A is a greater the”);
else
printf(B is a less then);
getch();
}
write a pgm using logical operation to find out that a person has insurence policy or not
1) if married
2)if unmaried – gender-male
age more than 30 years
gender- female
age more than 23 years
can smone tell me completely.
show the solution at the vedio store new releases rent for 3.00 a night oldies rent 2.00 your sales clerk will enter 1 for new release 2 for oldies to be stored in the variable type OR write the statement s that would increment the appropriate counter variable keeping track of the number of new releases and oldies rented and add the appropriate amount to the variable keeping track of the current sale.
i wana need a help for solving this solution plz help me
I need loop (while, do while, do) in C program
sir .. can you help me.. plss..
using do/while loop write a program that computes and display the sum of all even positive input numbers. the program terminates if it reads a negative number..
sample input/ouput dialogue:
enter a number:1
enter a number:2
enter a number:3
enter a number:4
enter a number:-4
the sum of all even number(s) is:6
now na po.. ^_^
Prompt the users to enter the subject name and traverse the list of subjects and if the entered subject is in list, display the name of the subjects (English, Math, Science. French). Using only if/switch statements