Search
Log in
Latest topics
Statistics
We have 30 registered usersThe newest registered user is deigavr
Our users have posted a total of 191 messages in 126 subjects
Who is online?
In total there is 1 user online :: 0 Registered, 0 Hidden and 1 Guest None
Most users ever online was 125 on Wed Apr 07, 2021 9:18 am
5th proram
Page 1 of 1
5th proram
Theory
“A for loop is a programming language statement which allows code to be repeatedly executed. A for loop is classified as an iteration statement.”
For loop is almost universally held to be the most commonly used loop. This is extremely useful when you have to execute a given set of instruction a limited number of times with little or no changes. This loop will start with giving a variable a predefined value and then keep on executing the body part of the loop as long as the given condition is true. Every time the loop is executed, the variable gets a new value.
Task:
1. Write a program that prints the following using For loop.
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Coding
#include<stdio.h>
void main(void)
{
int i,j;
for(i=1;i<5;i++)
{
for(j=1;j<=i;j++)
printf("*\n");
}
for(i=4;i>=1;i--)
{
for(j=1;j<=i;j++)
printf("*\n");
}
}
2. Write a program using one dimensional array that calculates the sum and average of the five input values from the keyboard and prints the calculated sum and average.
Coding:
#include<stdio.h>
void main(void)
{
int a,i,j,s=0;
for(i=0;i<5;i++)
{
printf("ENTER NUMNBER");
scanf("%d",&j);
s=s+j;
}
printf("sum is %d",s);
a=s/5;
printf("average is =%d\n",a);
}
“A for loop is a programming language statement which allows code to be repeatedly executed. A for loop is classified as an iteration statement.”
For loop is almost universally held to be the most commonly used loop. This is extremely useful when you have to execute a given set of instruction a limited number of times with little or no changes. This loop will start with giving a variable a predefined value and then keep on executing the body part of the loop as long as the given condition is true. Every time the loop is executed, the variable gets a new value.
Task:
1. Write a program that prints the following using For loop.
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Coding
#include<stdio.h>
void main(void)
{
int i,j;
for(i=1;i<5;i++)
{
for(j=1;j<=i;j++)
printf("*\n");
}
for(i=4;i>=1;i--)
{
for(j=1;j<=i;j++)
printf("*\n");
}
}
2. Write a program using one dimensional array that calculates the sum and average of the five input values from the keyboard and prints the calculated sum and average.
Coding:
#include<stdio.h>
void main(void)
{
int a,i,j,s=0;
for(i=0;i<5;i++)
{
printf("ENTER NUMNBER");
scanf("%d",&j);
s=s+j;
}
printf("sum is %d",s);
a=s/5;
printf("average is =%d\n",a);
}
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Mon Aug 01, 2011 11:44 pm by Guest
» Netbook Brands
Mon Aug 01, 2011 5:39 am by Guest
» backlinks checker backlink service
Sun Jul 31, 2011 8:56 am by Guest
» how to buy facebook fans f4
Sat Jul 30, 2011 2:34 pm by Guest
» Alle bijzondere dingen in de zaanstreek
Sat Jul 30, 2011 8:11 am by Guest
» HERE YOU CAN POST ALL WEBSITE LINKS...
Wed Aug 26, 2009 2:16 pm by onesimpletech
» cool web site for all must check it
Mon Jul 06, 2009 2:32 pm by Snopy Cobra
» poetry spirit
Mon Jul 06, 2009 2:31 pm by Snopy Cobra
» best to learn VC++
Sun May 10, 2009 3:22 pm by Guest