main()
{
int i,n,sum=0;
float avg=0.0;
printf("\nInput 10 Numbers : ");
for(i=1;i<=10;++i)
{
scanf("%d",&n);
sum+=n;
}
avg=sum/10.0;
printf("Sum=%d\nAvg=%f",sum,avg);
}
Write the C Program. Print the following format
Write the C Program. Print the following format
First few numbers: 0,1,1,2,3,5,8,13,21,34
Sequence and Formula:
The sequence starts with f=0 & f1=1
Every subsequent number is by adding the two numbers before it.
f2= 0+1 -> 1 1+1 ->2 1+2 -> 3 ........
Loops in C are control flow
statements that facilitate the repeated execution of a block of code based on a
specified condition. C provides three primary types of loops: for loop, while
loop and do-while loop.
for loop
Simple for loop
Syntax
for(initial value; condition; increment/decrement)
{
statements;
}
The for statement followed three statements in the parenthesis separated by semi-colon (;).
Initialization of the variables to
execute once.
Conditional statement: It will check
the condition, if it is true then body part of the loop will be executed.
Increment/decrement statements: After
the condition check, increment/decrement statement is executed and once again
the condition is evaluated.
Ex.
output 1 2 3 4 5 6 7 8 9 10
Nested loop
Loop in loop is called nested loop
Syntax
for(initial value; condition; increment/decrement)
for(initial value; condition; increment/decrement)
statement;