Posts

Find factorial of a given number using the recursive function method in C

Image
Write a program to find factorial of a given number using the recursive function method in C Hints: Factorial ! Example: 4! is shorthand for 4 x 3 x 2 x 1 The factorial function (symbol: ! ) means to multiply a series of descending natural numbers. Examples: 4! = 4 × 3 × 2 × 1 = 24 7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5040 1! = 1 Source Code: #include<stdio.h> //function declaration before the main int factorial(int n); //main function of the program int main() {     int n;     scanf("%d",&n);     //call function and print the final value at a time     printf("%d", factorial(n));     return 0; } int factorial(int n) {     if(n!=1)      return n*factorial(n-1); }

Write a c program to sum of all elements from a two dimensional (2D) array

Image
Figure of a Two Dimensional Array: Program:

Print the multiplication table

Example: 2 x 1 =2 2 x 2=4 2 x 3=6 2 x 4=8 2 x 5=10 etc

Sum of 1st 10 Prime Number

WAP to print sum of 1st 10 prime numbers starting from 1.

Sum of each consequent 5 even number

Print sum for each consequent 5 even numbers starting from 1. The loop will continue up to the 100. Example of  Output: Sum: 30 [2,4,6,8,10 are the first 5 even number] Sum: 90 etc.

Nesting of for loops : Pyramid Drawing

Nesting of loops, that is, one for statement within another for statement, is allowed in C. Theme: Inner Loop and Outer Loop Practice Using For in C   Write a C Program to print half pyramid using * as shown in figure below.   * * * * * * * * * * * * * * * main () { int i , 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" ); } return 0 ; }         Print half pyramid using numbers as shown in figure below . 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5   main () { int i , 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 " ,

EVEN NUMBER

Q. Write a C Program to check whether the given number is Even or Not. #include<stdio.h> main() {     int num;     scanf("%d",&num);     if(num%2==0)     printf("Even Number");     else     printf("ODD Number");     } Q. Write a C Program to Print first 10 Even Number starting from 1. Use For Loop, If-Else and Break; #include<stdio.h> main() {         int i,cnt=0;         for(i=1; ;i++)         {             if (i%2==0)                 {                 cnt=cnt+1;                 if (cnt<=10)                     printf("%d ",i);                 else                     break;                 }         } }