Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
int s1,s2,s3,s4,s5;
float per;
/*Program to enter item details and print its bill with complete
details according to the discount offered to the customer */
#include<iostream.h>
char name[20];
#include<conio.h>
cout<<"\n Enter student's Name and Roll number";
main()
cin>>name>>roll;
{
cout<<"\n Enter student marks in Physics, Chemistry, Maths,
English, Physical";
int itcd;
cin>>s1>>s2>>s3>>s4>>s5;
float pr,qty,d,dp,amt,tamt;
per=(s1+s2+s3+s4+s5)/5.0;
char itnm[10];
cin>>itnm>>itcd;
if(amt>=500)
{
d=12.5;
dp=amt*d/100;
tamt=amt-dp;
cout<<"\n
Code\tName\tQty.\tPrice\tAmount\tDis%\tT.Amount";
cout<<"\n
"<<itcd<<"\t"<<itnm<<"\t"<<qty<<"\t"<<pr<<"\t"<<am
t<<"\t"<<d<<"\t"<<tamt;
}
else
{
d=7.5;
dp=amt*d/100;
tamt=amt-dp;
cout<<"\n
Code\tName\tQty.\tPrice\tAmount\tDis%\tT.Amount";
cout<<"\n
"<<itcd<<"\t"<<itnm<<"\t"<<qty<<"\t"<<pr<<"\t"<<am
t<<"\t"<<d<<"\t"<<tamt;
}
getch();
}
/*Program to enter students name, roll number and its percentage and
allot his division*/
#include<stdio.h>
#include<conio.h>
void main()
{
int roll;
char nm[40];
float percent;
printf("\n enter students name and roll number");
scanf("%s%d",nm,&roll);
printf("\n enter percentage of the student");
scanf("%f",&percent);
if(percent>=60.0)
printf("\n student obtain first division");
else if(percent>=50.0 || percent<60.0)
printf("\n student obtain second division");
else if(percent>=35.0 || percent<50.0)
printf("\n student obtain third division");
else
printf("\n student is fail");
getch();
}
r=n%10;
These are used for repeating some portion of the program either
by specified number of times or until a particular condition is true.
1. while statement
2. do while statement
3. for loop
n=n/10;
sum=sum+r;
while loop
This loop is that in which we can execute a set of statements again and
again starting from given starting value of the variable up-to that value
of the variable which is given in the termination condition.
While loop starts with the the keyword while followed by expression
and a block is used there after it includes set of statements. Its format
is:
while(expression)
{
Statement1;
Statement2;
Statement3;
}
In this while loop starting value of the variable is initialized above the
loop. Termination condition is given with the while keyword and
increment and decrement of the variable takes place inside the loop.
}
cout<<"\n Sum of digits of number "<<n1<<" is "<<sum;
getch();
}
Do while looping
This loop is also an inbuilt structure in the language and it is just like for
loop and while loop. But this loop is different from while loop because
while loop checks the terminating condition at the top but this loop checks
the condition at the bottom. This loop is a free entry loop and unlike while
loop this loop will execute at least once even if the condition is false.
Some basic difference is:
/* Program to enter limit and find sum of series upto that limit */
/* Program to enter limit by the user and find sum upto limit */
#include<iostream.h>
#include<conio.h>
main()
{
int n,sum=0,r,n1;
cout<<"\n Enter any number whose sum is to be found";
cin>>n;
n1=n;
while(n>0)
{
r=n%10;
n=n/10;
sum=sum+r;
}
cout<<"\n Sum of digits of number "<<n1<<" is "<<sum;
getch();
#include<iostream.h>
#include<conio.h>
main()
{
int n,sum=0,r,n1;
cout<<"\n Enter any number to find its digit sum";
cin>>n;
}
n1=n;
/* Program to enter a number and find sum of its digits*/
do
#include<iostream.h>
{
#include<conio.h>
r=n%10;
main()
n=n/10;
{
sum=sum+r;
int n,sum=0,r,n1;
}
cout<<"\n Enter any number whose sum is to be found";
while(n>0);
cin>>n;
cout<<"\n Sum of digits of "<<n1<<" is "<<sum;
n1=n;
getch();
while(n>0)
}
{