0% found this document useful (0 votes)
6 views

Practice Programs Based on for Loop,Nested Loops

The document contains multiple C programs demonstrating various programming concepts. It includes programs to print numbers, even numbers, Fibonacci sequences, nested loops, multiplication tables, and a pattern of asterisks. Each program is structured with appropriate input and output statements.

Uploaded by

Vaibhav Kulkarni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Practice Programs Based on for Loop,Nested Loops

The document contains multiple C programs demonstrating various programming concepts. It includes programs to print numbers, even numbers, Fibonacci sequences, nested loops, multiplication tables, and a pattern of asterisks. Each program is structured with appropriate input and output statements.

Uploaded by

Vaibhav Kulkarni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

/* Program to print numbers from 1 to 5 using for loop*/

#include<stdio.h>
int main()
{
int i;

for(i=1;i<=5;i++)
{
printf("\t %d",i);
}

printf("\n End of Program");


return 0;
}

/* Program to print even numbers between 1 and n using for loop */


#include<stdio.h>
int main()
{
int i,n;

printf("\n Enter the value of n");


scanf("%d",&n);

for(i=1;i<n;i++)
{
if(i%2==0)
printf("\n %d",i);
}

printf("\n end of Program");


return 0;

}
//Program to generate and display the first n fibonacci numbers.

#include<stdio.h>
int main()
{
int f1,f2,f3,n,i;
printf("Enter number");
scanf("%d",&n);

f1=0;
f2=1;

printf("\n FIBBONACCI Sequence : \n");


printf("%d\n",f1);
printf("%d\n",f2);

for(i=3;i<=n;i++)
{
f3=f1+f2;
printf("%d\n",f3);
f1=f2;
f2=f3;
}
return 0;
}
//Program to demonstrate nested loops.
#include <stdio.h>
int main()
{
int i,j;
i=1;
while(i<=5)
{
j=1;
while(j<=3)
{
printf("Hello\t");
j++;
}
printf("\n");
i++;
}
return 0;
}
/* Write a Program to display the tables from 1 to n using nested
while loops */

#include <stdio.h>
int main()
{
int num,cnt,i,result=1;
printf("Enter a positive integer: ");
scanf("%d", &num);

i=1;
while(i<=num)
{
cnt=1;
while(cnt<=10)
{
result=i*cnt;
printf("\n %d * %d=%d",i,cnt,result);
cnt++;
}
printf("\n");
i++;
}
return 0;
}

//Write a program to print the * pattern


#include <stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}

You might also like