0% found this document useful (0 votes)
17 views9 pages

Programs

The documents contain C code for printing multiplication tables and patterns using loops like for loops and while loops. Some programs take user input for the number to print the table of, while others hardcode the number or use arrays. Loops are used with nested loops and conditions to print the patterns in different formats like triangles, numbers, and symbols.

Uploaded by

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

Programs

The documents contain C code for printing multiplication tables and patterns using loops like for loops and while loops. Some programs take user input for the number to print the table of, while others hardcode the number or use arrays. Loops are used with nested loops and conditions to print the patterns in different formats like triangles, numbers, and symbols.

Uploaded by

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

#include <stdio.

h>

int main()
{
int a ;
scanf("%d",&a);
for (int i=1;i<=10;i++)
printf("%d*%d=%d\n",a,i, a*i);
}

output : table

#include <stdio.h>

int main()
{
int a=1;
for (int i=1;i<=10;i++)
{

for (int j=1;j<=i;j++)


{
printf("%d", a);
a++;
} printf("\n");
}
}

output :
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55

#include <stdio.h>

int main()
{
for (int i=1;i<=4;i++)
{
for (int j=1;j<=i;j++)
{
if ((i+j)%2==0)
{
printf("1");
}
else
{
printf("0");
}
} printf("\n");
}
}

output :
1
01
101
0101

#include <stdio.h>
int main()
{
for (int i=1;i<=100;i++){
int a=0;
for(int j=2;j<=i/2;j++)
{
if(i%j==0){
a++;
}
}
if(a==0 && i!=1)
{
printf("%d\n",i);
}
}
}
output :
3
5
7
11
13
17
19
23
29
31
37
41
43
#include <stdio.h>

#include <stdio.h>

int main()
{
int a=1;
for (int i=1;i<=10;i++)
{

for (int j=1;j<=i;j++)


{
printf("%d ", a*a);
a++;
} printf("\n");
}
}

output :
1
4 9
16 25 36
49 64 81 100
121 144 169 196 225
256 289 324 361 400 441

to print the 7th prime no.

#include <stdio.h>
int main()
{
int b=6;
for (int i=1;i<=100;i++){
int a=0;
for(int j=2;j<=i/2;j++)
{
if(i%j==0){
a++;
}
}
if(a==0 && i!=1)
{
b++;
if(b==7){
printf("%d\n",i);
b=1;
}
}
}
}

output:
2
17
41
67
97

#include <stdio.h>

int main()
{
for (int i=1;i<=6;i++)
{

for (int j=i;j>=1;j--)

{
printf("%d", j);

} printf("\n");
}
}

output :
1
21
321
4321
54321
654321

#include <stdio.h>

int main()
{
for (int i=1;i<=6;i++)
{
for (int k=6;k>i;k--)
{
printf(" ");

for (int j=1;j<=i;j++) {


printf("%d", j);

} printf("\n");
}
}

output :

1
12
123
1234
12345
123456
#include <stdio.h>

int main()
{

for (int i=1;i<=5;i++)


{
for (int k=5;k>i;k--)
{
printf("-");

for (int j=1;j<=i;j++) {


printf("*");

}
for (int j=2;j<=i;j++)

{
printf("*");

printf("\n");

}
}

output:

----*
---***
--*****
-*******
*********

#include <stdio.h>

int main() {
int k;
for(int i=1;i<=5;i++){
for(int j=5;j>i;j--){

printf("-");
}
for(k=1;k<=i;k++){
printf("%d",k);
}

for(k=i-1;k>=1;k--){

printf("%d",k);

printf("\n") ;
}

//5th
for(int i=4;i>=1;i--){
for(int j=5;j>i;j--){

printf("-");
}
for(k=1;k<=i;k++){
printf("%d",k);
}

for(k=i-1;k>=1;k--){

printf("%d",k);

printf("\n") ;
}
}

output :

----1
---121
--12321
-1234321
123454321
-1234321
--12321
---121
----1

// Online C compiler to run C program online


#include <stdio.h>

int main() {
int k;
for(int i=1;i<=5;i++){
for(int j=5;j>i;j--){

printf("-");
}
for(k=1;k<=i;k++){
printf("%d",k);
}

for(k=i-1;k>=1;k--){

printf("%d",k);

}
for(int j=5;j>i;j--){

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

for(k=i-1;k>=1;k--){

printf("%d",k);

printf("\n") ;
}

//5th
for(int i=4;i>=1;i--){
for(int j=5;j>i;j--){

printf("-");
}
for(k=1;k<=i;k++){
printf("%d",k);
}

for(k=i-1;k>=1;k--){

printf("%d",k);

}
for(int j=5;j>i;j--){

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

for(k=i-1;k>=1;k--){

printf("%d",k);

printf("\n") ;
}
}

#include <stdio.h>

int main()
{
int a,i=1 ;
scanf("%d",&a);
while(i<=10){

printf("%d*%d=%d\n",a,i, a*i);
i++;
}

output : table ( using while loop )

#include <stdio.h>

int main()
{
int a,i=1 ;
scanf("%d",&a);
while(i<=10){

printf("%d*%d=%d\n",a,i, a*i);
i++;
}

output :

----1 1
---121 121
--12321 12321
-1234321 1234321
123454321123454321
-1234321 1234321
--12321 12321
---121 121
----1 1

#include <stdio.h>
int main()
{
int a,i=1 ;
scanf("%d",&a);
do{
printf("%d*%d=%d\n",a,i,a*i);
i++;
}
while(i<=10);{
}

output: table using do while loop

#include <stdio.h>
int main()
{
int arr[10];
int a,i;
for(i=0,a=1;i<10;i++,a++)
{
arr[i]= a*8;
}
for(i=0;i<10;i++)
{
printf("%d\n", arr[i]);}
}

output: table using array

#include <stdio.h>
int main()
{
int arr[]={1,2,3,4,5};
int a,i;
for(i=0;i<5;i++)
{
arr[i]= arr[i]*8;
}
for(i=0;i<5;i++)
{
printf("%d\n", arr[i]);}
}

output: print table using stored value in array

You might also like