You are on page 1of 14

Experiment no.

4
Name of student:
Year:
Branch:
Div:
Roll no:
Date of performing:
Date of submission:
Practical 1
Aim: Program of Simple Interest With while Loop (Increment Value of
i)
Source code:
# include <stdio.h>
int main( )
{
int p, n, count, r, si ;
count = 1 ;
while ( count <= 3 )
{
printf ("Client %d \n", count);
printf ( "Enter values of Principle = Rs." ) ;
scanf ( "%d", &p ) ;
printf ( "Enter Number of Years = " ) ;
scanf ( "%d",&n) ;
printf ( "Enter Rate of Interest = " ) ;
scanf ( "%d",&r) ;
si = p * n * r / 100 ;
printf ( "Simple interest = Rs. %d\n", si ) ;
count = count + 1 ;
}
return 0 ;
}
Input and Output:
Client 1
Enter values of Principle = Rs. 10000
10000
Enter Number of Years = 5
Enter Rate of Interest = 8
Simple interest = Rs. 4000
Client 2
Enter values of Principle = Rs.1000
Enter Number of Years = 5
Enter Rate of Interest = 10
Simple interest = Rs. 500
Client 3
Enter values of Principle = Rs.55
Enter Number of Years = 5
Enter Rate of Interest = 100
Simple interest = Rs. 275

Code conclusion: code executed properly

Signature:
Practical 2
Aim: Program of Simple Interest With while Loop (Decrement Value
of i )
Source code:
# include <stdio.h>
int main( )
{
int p, n, count, r, si ;
count = 3 ;
while ( count > 0 )
{
printf ("Client %d \n", count);
printf ( "Enter values of Principle = Rs." ) ;
scanf ( "%d", &p ) ;
printf ( "Enter Number of Years = " ) ;
scanf ( "%d",&n) ;
printf ( "Enter Rate of Interest = " ) ;
scanf ( "%d",&r) ;
si = p * n * r / 100 ;
printf ( "Simple interest = Rs. %d\n", si ) ;
count = count - 1 ;
}
return 0 ;
}
Input and output:
Client 3
Enter values of Principle = Rs.10
Enter Number of Years = 1
Enter Rate of Interest = 100
Simple interest = Rs. 10
Client 2
Enter values of Principle = Rs.20000
Enter Number of Years = 5
Enter Rate of Interest = 4
Simple interest = Rs. 4000
Client 1
Enter values of Principle = Rs.600
Enter Number of Years = 52
Enter Rate of Interest = 8
Simple interest = Rs. 2496

Code conclusion: code executed properly

Signature:
Practical 3
Aim: Program To Print Infinite Number of “1” Using While
Source code:
# include <stdio.h>
int main( )
{
int i = 1 ;
while ( i <= 10 )
printf ( "%d\n", i ) ;
return 0 ;
}
Input&Output:
1
1
1
.
.
.
infinite

Code conclusion: code executed properly

Signature:
Practical 4
Aim: Program To Print Infinite Number Using While & if Else.
Source code:
# include <stdio.h>
int main( )
{
int i ;
printf ("Enter The Value of n = ");
scanf ("%d", &i);
if (i<=10)
{
while ( i <= 10 )
printf ( "%d\n", i ) ;
}
else
{
printf ("Re-enter The Number. You Have Entered Number More Than 10");
}
return 0 ;
}
Input:
Enter the value of number= 10
Output:
10
10
10
.
.
.
infinite

Code conclusion: code executed properly

Signature:
Practical 5.1
Aim: What Is The Output of This Program. Comment Without
Executing
Source code:
# include <stdio.h>
int main( )
{
int i = 1 ;
while ( i <=10)
{
printf ( "%d \n ", i ) ;
i=i+1;
}
return 0 ;
}
Input and Output:
1
2
3
4
5
6
7
8
9
10

Code conclusion: code executed properly

Signature:
Practical 5.2
Aim: To Print First 10 Numbers Using While. Type 1
Source code:
# include <stdio.h>
int main( )
{
int i = 1 ;
while ( i <= 10 )
{
printf ( "%d\n", i ) ;
i++ ;
}
return 0 ;
}
Input and Output:
1
2
3
4
5
6
7
8
9
10

Code conclusion: code executed properly

Signature:
Practical 5.3
Aim: To Print First 10 Numbers Using While. Type 2
Source code:
# include <stdio.h>
int main( )
{
int i = 1 ;
while ( i <= 10 )
{
printf ( "%d\n", i ) ;
i += 1 ;
}
return 0 ;
}
Input and Output:
1
2
3
4
5
6
7
8
9
10

Code conclusion: code executed properly

Signature:
Practical 5.4
Aim: To Print First 10 Numbers Using While. Type 3 (Using Compound
Operator)
Source code:
# include <stdio.h>
int main( )
{
int i = 0 ;
while ( i++ < 10 )
printf ( "%d\n", i ) ;
return 0 ;
}
Input and Output:
1
2
3
4
5
6
7
8
9
10

Code conclusion: code executed properly

Signature:
Practical 5.5
Aim: To Print First 10 Numbers Using While. Type 4 (Using while(i++..)
Operator)
Source code:
# include <stdio.h>
int main( )
{
int i = 0 ;
while ( ++i <= 10 )
printf ( "%d\n", i ) ;
return 0 ;
}
Input and Output:
1
2
3
4
5
6
7
8
9
10

Code conclusion: code executed properly

Signature:
Practical 6
Aim: Using while Loop With Decrement Values.
Source code:
# include <stdio.h>
int main( )
{
int i = 5 ;
while ( i >= 1 )
{
printf ( “Tu Hushar Ahes Mitra!\n" ) ;
i=i-1;
}
}
Input and Output:
Tu Hushar Ahes Mitra!
Tu Hushar Ahes Mitra!
Tu Hushar Ahes Mitra!
Tu Hushar Ahes Mitra!
Tu Hushar Ahes Mitra!

Code conclusion: code executed properly

Signature:
Practical 7
Aim: Program With while Loop and FLOAT value.
Source code:
# include <stdio.h>
int main( )
{
float a = 10.0 ;
while ( a <= 10.5 )
{
printf ( "Tu Hushar Ahes Mitra Ani.." ) ;
printf ( "..Ani Kadak Programing Pan Kartos.." ) ;
printf ( "..Kya Bat Hai..Wah.. Bohut Acheee\n\n" ) ;
a = a + 0.1 ;
}
return 0 ;
}
Result:
Tu Hushar Ahes Mitra Ani....Ani Kadak Programing Pan Kartos....Kya Bat Hai..Wah.. Bohut
Acheee
Tu Hushar Ahes Mitra Ani....Ani Kadak Programing Pan Kartos....Kya Bat Hai..Wah.. Bohut
Acheee
Tu Hushar Ahes Mitra Ani....Ani Kadak Programing Pan Kartos....Kya Bat Hai..Wah.. Bohut
Acheee
Tu Hushar Ahes Mitra Ani....Ani Kadak Programing Pan Kartos....Kya Bat Hai..Wah.. Bohut
Acheee
Tu Hushar Ahes Mitra Ani....Ani Kadak Programing Pan Kartos....Kya Bat Hai..Wah.. Bohut
Acheee

Code conclusion: code executed properly


Experiment conclusion: All the variations of while loop with if , else
function combinations and basic programs are understood and
executed by students.

Signature:

You might also like