C Program To display the triangle using *, numbers and character
Write a C Program to print half pyramid as using * as shown in figure below.
***************
#include<stdio.h>intmain(){inti,j,rows;
printf("Enter the number of rows: ");
scanf("%d",&rows);for(i=1;i<=rows;++i){for(j=1;j<=i;++j){
printf("* ");}
printf("\n");}return0;}
Write a C Program to print half pyramid as using numbers as shown in figure below.
112123123412345
#include<stdio.h>intmain(){inti,j,rows;
printf("Enter the number of rows: ");
scanf("%d",&rows);for(i=1;i<=rows;++i){for(j=1;j<=i;++j){
printf("%d ",j);}
printf("\n");}return0;}
Write a C Program to print triangle of characters as below
A
B B
C C C
D D D D
E E E E E
#include<stdio.h>intmain(){inti,j;charinput,temp='A';
printf("Enter uppercase character you want in triangle at last row: ");
scanf("%c",&input);for(i=1;i<=(input-'A'+1);++i){for(j=1;j<=i;++j) printf("%c",temp);++temp;
printf("\n");}return0;}
C Program to Draw Pascal's triangle
11112113311464115101051
#include<stdio.h>intmain(){introws,coef=1,space,i,j;
printf("Enter number of rows: ");
scanf("%d",&rows);for(i=0;i<rows;i++){for(space=1;space<=rows-i;space++)
printf(" ");for(j=0;j<=i;j++){if(j==0||i==0)
coef=1;else
coef=coef*(i-j+1)/j;
printf("%4d",coef);}
printf("\n");}}
Fibonacci series in c Fibonacci series in c programming: c program for Fibonacci series without and with recursion. Using the code below you can print as many numbers of terms of series as desired. Numbers of Fibonacci sequence are known as Fibonacci numbers. First few numbers of series are 0, 1, 1, 2, 3, 5, 8 etc, Except first two terms in sequence every other term is the sum of two previous terms, For example 8 = 3 + 5 (addition of 3, 5). This sequence has many applications in mathematics and Computer Science. Fibonacci series in c using for loop /* Fibonacci Series c language */ #include <stdio.h> int main ( ) { int n , first = 0 , second = 1 , next , c ; printf ( "Enter the number of terms \n " ) ; scanf ( "%d" ,& n ) ; printf ( "First %d ...
Program to reverse the array. #include <stdio.h> void main() { int n, c, a[100],; printf( "Enter the number of elements in array\n" ); scanf( "%d" , &n); printf( "Enter the array elements\n" ); for (c = 0; c < n ; c++) scanf( "%d" , & a[c] ); pdrintf( "Reversed array is \n" ); for (c=n;c>=0;c--) printf( "%5d" , a[c] ); getch(); } Output:
To Find Factorial of a Number Factorial of a Number For any positive number n , its factorial is given by: factorial = 1 * 2 * 3 * 4. ... n If a number is negative, factorial does not exist and factorial of 0 is 1. This program takes an integer from a user. If user enters negative integer, this program will display error message and if user enters non-negative integer, this program will display the factorial of that number. Source Code /* C program to display factorial of an integer if user enters non-negative integer. */ #include <stdio.h> int main () { int n , count ; unsigned long long int factorial = 1 ; /* you can only write int */ printf ( "\nEnter an integer: \n" ); scanf ( "%d" ,& n ); if ( n < 0 ) printf ( "\nError!!! Factorial of negative number doesn't e...
Comments
Post a Comment