Posts

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;                 }         } }

Difference between while & do while loops in C

C  Loop control statement Loop control statements in C are used to perform looping operations until the given condition is true. Control comes out of the loop statements once condition becomes false. Types of loop control statements in C: There are 3 types of loop control statements in C language. They are, for while do-while   Example program (For Loop) in C: #include <stdio.h> int main() { int i; for(i=0;i<10;i++) { printf("%d ",i); } } 1 2 3 4 5 6 7 8 9 10 11 12 #include <stdio.h>   int main ( ) {    int i ;      for ( i = 0 ; i < 10 ; i ++ )    {        printf ( "%d " , i ) ;    }        } Output: 0 1 2 3 4 5 6 7 8 9 Example program (while loop) in C:       In while loop control statement, loop is executed until condition becomes false . #include <stdio.h> int main() {

Special Operator in C

Special Operators in C: Below are some of special operators that C language offers.  S.no Operators Description 1 & This is used to get the address of the variable. Example : &a will give address of a. 2 * This is used as pointer to a variable. Example : * a  where, * is pointer to the variable a. 3 Sizeof () This gives the size of the variable. Example : size of (char) will give us 1. Example program for & and * operators in C: In this program, “&” symbol is used to get the address of the variable and “*” symbol is used to get the value of the variable that the pointer is pointing to.  #include <stdio.h> int main() { int *ptr, q; q = 50; /* address of q is assigned to ptr */ ptr = &q; /* display q's value using ptr variable */ printf("%d", *ptr); return 0; } #include <std