Write a program in C language using for loop.

For loop:- C language Program

For loop is the iterations that is used to execute a sequence of code until the given condition returns false. The best condition to use for loop is when the number of iterations is known in advance.

Synstex of the for loop

for(initialise; condition ; increment/decrement)

{

// Statements inside the body of loop;

}

1-Write a c-language program to print numbers from 1 to 10 using for loop.

looping c language, c++, programming, programming python pdf, programming r, programming aptitude test, c program to find sum of n numbers using for loop, c program to find sum of n numbers using function, sum of numbers from 1 to 100 in c, c program for sum of two numbers, c program to find multiples of a number, c program to find sum of n numbers using array, c program to find sum of 10 numbers using function, how to find multiples of a number in c++, Programming 5 axis cnc, java web services rest, java spring tutorial, java rest api,java point, java virtual machine, java executor framework, java for windows 7, restful  web services java, java web services soap, java 8 download, programming game ai by example, programming questions in java, programming quotes, programming for problem solving, programming with mosh, programming near me, programming in visual basic,
for loop

#include(stdio.h)

#include(conio.h)

Int main()

{

int i;

clrscr();

for(i= 1; i<11; i++)

{

Printf (“%d”, i);

}

getch();

}

Output:- 12345678910


Write a C-language program for Addition,Substraction,Multiplication and Division.


2- Write a c language program to calculate the sum of first n natural numbers 

#include(stdio.h)

#include(conio.h)

Int main ()

{

int num, count, sum=0;

printf(“Enter a positive number”);

scanf(“%d”, &num);

for(count=1; count<=num; ++count)

{

sum +=count;

}

Printf(“sum=%d”,sum);

getch();

}

Output :- Enter a positive number: 10

Sum= 55


3-Write a c language program of factorial program in c using for loop.


#include<stdio.h>

#include<conio.h>

int main ()

{

int i, f=1, num;

printf(“Enter a number:-”);

scanf(“%d”, &num);

for (i=1; i<=num; i++)

f=f*1;

printf (“Factorial of %d is: %d”, num, f);

getch ();

}

Output:-

Enter a number:- 5

Factorial of 5 is :- 120

4-Write a program in c language to print multiple of 2 from 2 to 20.

#include(stdio.h)

#include(conio.h)

int main()

{

int count;

for(count=1;count<=20; count++)

{

If(count%2==1)

{

continue;

}

printf(“%d”,count);

}

getch();

}

Output:- 2 4 6 8 10 12 14 16 18 20

5- Write a program in c language of a triangle pattern using for loop.


#include(stdio.h)

#include(conio.h)

Int main()

{

int i, k, rows , blank;

printf(“ Enter the number of rows:”);

scanf(“%d”,&row);

blank = rows;

for(i=1; i<= rows ;i++)

{

for(k=1; k<blank; k++)

printf(“ ”);

blank- -;

for( k=1; k<= 2*i – 1 ; k ++)

printf(“ * ”);

printf(“ \n”);

}

getch();

}

Output:- Enter the number of rows : 4

              *

           * * *

        * * * * *

Post a Comment

0 Comments