c loop programs

      Comments Off on c loop programs

c loop programs

c loop programs

c loop programs is collection of loop programs I have prepared during my MCA. I am sharing this program with all of you that It might be useful to someone who has just started working on C Language to built their Logic. If you want to download all programs then goto bottom of the page and click on download link.

Have you check, C Pattern Tutorial?

C Sample Program on Loop 1

//Written by Adarsh Patel
//dispaly number from  1 to n using c for loop

#include <stdio.h>
#include <conio.h>
void main()
{
	clrscr();

	int n,i;

	printf("Enter Number of Terms : ");
	scanf("%d",&n);

	for(i=1;i<=n;i++)
	printf("%d ",i);

	getch();
}

 

C Sample Program on Loop 2

//Written by Adarsh Patel
//dispaly numbers from n to 1 using for loop (reverse for loop example in c language)

#include <stdio.h>
#include <conio.h>
void main()
{
	clrscr();

	int n,i;

	printf("Enter Number of Terms : ");
	scanf("%d",&n);

	for(i=n;i>=1;i--)
	printf("%d ",i);

	getch();
}

 

 

C Sample Program on Loop 3

//Written by Adarsh Patel
//display alternate numbers using c for loop

#include <stdio.h>
#include <conio.h>
void main()
{
	clrscr();

	int n,i;

	printf("Enter Number of Terms : ");
	scanf("%d",&n);

	for(i=1;i<=n*2;i=i+2)
	printf("%d ",i);

	getch();
}

 

C Sample Program on Loop 4

//Written by Adarsh Patel
//display only numbers which is divisible by some numbers in c language

#include <stdio.h>
#include <conio.h>
void main()
{
	clrscr();

	int n,i;

	printf("Enter Last Number : ");
	scanf("%d",&n);

	printf("\n\t: Below Shown Numbers are Divisible by 7 and 5 :\n\n");

	for(i=1;i<=n;i++)
	{
		if(i%7==0 && i%5==0)
			printf("\t%4d",i);

	}

	getch();
}

 

C Sample Program on Loop 5

//Written by Adarsh Patel
//display only numbers which is divisible by some numbers in c language

#include <stdio.h>
#include <conio.h>
void main()
{
	clrscr();

	int n,i,count=0;

	printf("Enter Last Number : ");
	scanf("%d",&n);

	printf("\n\t\t: Divisible by 6 But Not by 3 :\n\n");

	for(i=1;i<=n;i++)
	{
		if(i%3==0 && i%6!=0)
		{
			count++;
			printf("\t%4d",i);

			if(count%6==0)
				printf("\n");
		}
	}

	getch();
}

 

C Sample Program on Loop 6

//Written by Adarsh Patel
//find sum of 1 to N numbers using for loop

#include <stdio.h>
#include <conio.h>
void main()
{
	clrscr();

	int n,i,sum=0;

	printf("Enter Number : ");
	scanf("%d",&n);

	for(i=1;i<=n;i++)
		sum=sum+i;

	printf("Sum of Up To %d Number is : %d",n,sum);

	getch();
}

 

 

 

C Sample Program on Loop : Download All Loop Programs

[sociallocker]Download[/sociallocker]