structure of for loop
for(initial=value;condition;increment)
instruction;
Now for an example:
main()
{
int row,column;
puts("\t\tMY Handy multipication table");
for(row=1;tow<=10;row++)
{ for(column=1;column<=10;column++)
printf("%6d", row*column);
putchar('\n');
}
}
The output is a multipication table of 10x10 size.
Level/s:4
* * * *
* * *
* *
*
#include <stdio.h>
#include <conio.h>
int main()
{
int M,N;
printf("enter the ranges do you want diaplay\n");
scanf("%d%d",&M,&N);
printf("the numbers between %d to %d \n",M,N);
for(;M<=N;M++)
printf("%d ",M);
getch();
}
Display the leap Years between 1000 and 2000
#include <stdio.h>
#include <conio.h>
int main()
{
int loop;
printf("the leap year or not between 1000 to 2000\n");
for(loop=1000;loop<=2000;loop++)
{
if(loop%4==0)
printf("%d leap year\n",loop);
else
printf("%d not\n",loop);
}
getch();
}
These program prints various different patterns of numbers and stars. These codes illustrate how to create various patterns using c programming. Most of these c programs involve usage of nested loops and space. A pattern of numbers, star or characters is a way of arranging these in some logical manner or they may form a sequence. Some of these patterns are triangles which have special importance in mathematics. Some patterns are symmetrical while other are not. Please see the complete page and look at comments for many different patterns.
for(initial=value;condition;increment)
instruction;
Now for an example:
example-7
{
int row,column;
puts("\t\tMY Handy multipication table");
for(row=1;tow<=10;row++)
{ for(column=1;column<=10;column++)
printf("%6d", row*column);
putchar('\n');
}
}
The output is a multipication table of 10x10 size.
Level/s:4
* * * *
* * *
* *
*
#include<stdio.h> #include<conio.h> main() { int z,a,b,c; clrscr(); printf("Level/s:"); scanf("%d",&c); for(z=c;z>=1;z--) { for(a=0;a<=z;a++) { printf(" "); } for(b=c;b>=1;b--) { printf("*"); } c=c-1; printf("\n "); } getch(); }
______________________________________________________________________________
#include <stdio.h>
#include <conio.h>
int main()
{
int M,N;
printf("enter the ranges do you want diaplay\n");
scanf("%d%d",&M,&N);
printf("the numbers between %d to %d \n",M,N);
for(;M<=N;M++)
printf("%d ",M);
getch();
}
Display the leap Years between 1000 and 2000
#include <stdio.h>
#include <conio.h>
int main()
{
int loop;
printf("the leap year or not between 1000 to 2000\n");
for(loop=1000;loop<=2000;loop++)
{
if(loop%4==0)
printf("%d leap year\n",loop);
else
printf("%d not\n",loop);
}
getch();
}
c program to print patterns of numbers and stars
* *** ***** ******* *********
#include<stdio.h>
main()
{
int row, c, n, temp;
printf("Enter the number of rows in pyramid of stars you wish to see ");
scanf("%d",&n);
temp = n;
for ( row = 1 ; row <= n ; row++ )
{
for ( c = 1 ; c < temp ; c++ )
printf(" ");
temp--;
for ( c = 1 ; c <= 2*row - 1 ; c++ )
printf("*");
printf("\n");
}
return 0;
}
12345 1234 123 12 1
#include<stdio.h> main() { int n, c, k, space; scanf("%d", &n); space = 0; for ( k = n ; k >= 1 ; k-- ) { for ( c = 1 ; c <= space ; c++ ) printf(" "); space++; for ( c = 1 ; c <= k ; c++) printf("%d", c); printf("\n"); } return 0; }
A B C D E F G H A B C D E F G A B C D E F A B C D E A B C D A B C A B A
#include<stdio.h> main() { char ch = 'A'; int n, c, k, space = 0; scanf("%d", &n); for ( k = n ; k >= 1 ; k-- ) { for ( c = 1 ; c <= space ; c++) printf(" "); space++; for ( c = 1 ; c <= k ; c++ ) { printf("%c ", ch); ch++; } printf("\n"); ch = 'A'; } return 0; }
1 01 010 1010 10101
#include<stdio.h> main() { int n, c, k, num = 1; scanf("%d", &n); for ( c = 1 ; c <= n ; c++ ) { for ( k = 1 ; k <= c ; k++ ) { printf("%d", num); if ( num == 0 ) num = 1; else num = 0; } printf("\n"); } return 0; }
p pr pro prog progr progra program
#include<stdio.h> #include<string.h> main() { char string[100]; int c, k, length; printf("Enter a string\n"); gets(string); length = strlen(string); for ( c = 0 ; c < length ; c++ ) { for( k = 0 ; k <= c ; k++ ) { printf("%c", string[k]); } printf("\n"); } return 0; }
1 121 12321 1234321 123454321
#include<stdio.h> main() { int n, c, k, x = 1; scanf("%d", &n); for ( c = 1 ; c <= n ; c++ ) { for ( k = 1 ; k <= c ; k++ ) { printf("%d", x); x++; } x--; for ( k = 1 ; k <= c - 1 ; k++ ) { x--; printf("%d", x); } printf("\n"); x = 1; } return 0; }
No comments:
Post a Comment