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

Program To Create Pyramid of Star in C: View Plain Print ?

The document contains code snippets for several C programs including: 1) A program to create a pyramid of stars that takes user input for number of rows. 2) A program to create a double pyramid that takes user input for number of rows. 3) A program to check if a string is a palindrome. 4) A program to multiply two 3x3 matrices. 5) A program to find the remainder without using the remainder operator. 6) A program to convert a decimal number to binary.

Uploaded by

Nazia Ahmad
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Program To Create Pyramid of Star in C: View Plain Print ?

The document contains code snippets for several C programs including: 1) A program to create a pyramid of stars that takes user input for number of rows. 2) A program to create a double pyramid that takes user input for number of rows. 3) A program to check if a string is a palindrome. 4) A program to multiply two 3x3 matrices. 5) A program to find the remainder without using the remainder operator. 6) A program to convert a decimal number to binary.

Uploaded by

Nazia Ahmad
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Program to create pyramid of Star in C

view plainprint?

1. #include<stdio.h>  
2. #include<conio.h>  
3. void main()  
4.      {  
5.        int i,j,k,s,n;  
6.        printf(" ENTER THE NO OF ROWS");  
7.        scanf("%d",&n);  
8.   
9.        for(i=1,s=n;i<=n;i++,s--)  
10.            {  
11.              for(k=1;k<=s;k++)  
12.                  printf(" ");  
13.              for(j=1;j<=i;j++)  
14.                  printf("*");  
15.               printf(" ");  
16.             }  
17.        getch();  
18.  }  
19.   
20. </conio.h></stdio.h> 

Program to create double pyramid in C

view plainprint?

1. #include<stdio.h>  
2. #include<conio.h>  
3. void main(void)  
4. {  
5.     clrscr();  
6.     int i,j,k,l,b,n;  
7.     printf("Enter the value of N:");  
8.     scanf("%d",&n);  
9.     for(i=0;i<=n;i++)  
10. {  
11.     printf(" ");  
12.     for(l=0;l<=i;l++)  
13.     printf(" ");  
14.     for(j=i+1;j<=n;j++)  
15.     printf("%d",j);  
16.     for(k=n-1;k>i;k--)  
17.     printf("%d",k);  
18. }  
19.     b=n-1;  
20.     for(i=0;i<=n-1;i++)  
21. {  
22.     printf(" ");  
23.     for(l=n-2;l>=i;l--)  
24.     printf(" ");  
25.     for(j=b;j<=n;j++)  
26.     printf("%d",j);  
27.     for(k=n-1;k>=b;k--)  
28.     printf("%d",k);  
29.     b--;  
30. }  
31.     getch();  
32. }  
33.   
34.   
35. </conio.h></stdio.h>  

Program to show Palindrome Verification in C, string is Palindrome or Not.

1. int palindrome( char* string )  
2.  {  
3.  int i = 0, j = strlen( string ) - 1;  
4.   
5.  while( i < j / 2 )   
6. {  
7.   
8.   if( string[ i++ ] == string[ j-- ] )  
9.        ;  
10.   else   
11. {  
12.    printf( "The String is not Palindrome" );  
13.    return -1;  
14.    }  
15.   }  
16.   
17.  printf( "The string is Palindrome" );  
18.  return 0;  
19.  }  
20.   
21.  int main( )  
22.  {  
23.  palindrome( "Info " );  
24.  palindrome( "Computers" );  
25.  return 0;  
26.  }  

Program to multiply two 3*3 matrices.

1. #include<stdio.h>  
2. #include<conio.h>  
3.   
4. /*Program to multiply two 3*3 matrices*/  
5.   
6. void main()  
7.  {  
8.   int a[3][3],b[3][3],c[3][3],i,j,k;  
9.   clrscr();  
10.   
11.   printf("Enter elements of A:");  
12.     for(i=0;i<=2;i++)  
13.      for(j=0;j<=2;j++)  
14.       scanf("%d",&a[i][j]);  
15.   
16.   printf("Enter elements of B:");  
17.     for(i=0;i<=2;i++)  
18.      for(j=0;j<=2;j++)  
19.       scanf("%d",&b[i][j]);  
20.   
21.    printf("A:");  
22.       for(i=0;i<=2;i++)  
23.       {  
24.        for(j=0;j<=2;j++)  
25.   printf("%d ",a[i][j]);  
26.  printf(" "); //To change line.  
27.        }  
28.   
29.     printf("B:");  
30.     for(i=0;i<=2;i++)  
31.     {  
32.      for(j=0;j<=2;j++)  
33.       printf("%d ",b[i][j]);  
34.      printf(" ");  
35.     }  
36.   k=0;  
37.    while(k<=2)  
38.    {  
39.     for(i=0;i<=2;i++)  
40.      {  
41.       int sum=0;  
42.       for(j=0;j<=2;j++)  
43.        sum=sum+a[i][j]*b[j][k];  
44.       c[i][k]=sum;  
45.      }  
46.     k++;  
47.    }  
48.   printf(" Result: ");  
49.   for(i=0;i<=2;i++)  
50.   {  
51.    for(j=0;j<=2;j++)  
52.     printf("%d ",c[i][j]);  
53.    printf(" ");  
54.   }  
55.   getch();  
56. }  
57. </conio.h></stdio.h>  

Program to find the reminder without using reminder in C

1. #include <stdio.h>  
2. #include <conio.h>  
3. main()  
4. {  
5. int a,b;  
6. clrscr();  
7. printf("enter the value of a=");  
8. scanf("%d",&a);  
9. printf("enter the value of b=");  
10. scanf("%d",&b);  
11. while(a-b>=b)  
12. {  
13. a=a-b;  
14. }  
15. printf("the reminder is =%d",a-b);  
16. getch();  
17. }  
18.   
19. </conio.h></stdio.h> 
decimal number into binary number system

1.  #include<stdio.h>  
2. #include<conio.h>  
3. #include<math.h>  
4.   
5. void dec_bin(long int num)   // Function Definition  
6. {  
7. long int rem[50],i=0,length=0;  
8. while(num>0)  
9.  {  
10.  rem[i]=num%2;  
11.  num=num/2;  
12.  i++;  
13.  length++;  
14.  }  
15. printf("\nBinary number : ");  
16.      for(i=length-1;i>=0;i--)  
17.              printf("%ld",rem[i]);  
18. }  
19. //================================================  
20. void main()  
21. {  
22. long int num;  
23. clrscr();  
24.    
25.  printf("Enter the decimal number : ");  
26.  scanf("%ld",&num);  
27.   
28.     dec_bin(num);   // Calling function  
29.   
30.  getch();  
31. }  
32.   
33.   
34. </math.h></conio.h></stdio.h>  

You might also like