Skip to main content

Posts

Showing posts from October, 2018

Write a 'c' program to find the sum of digits of a number using while loop

                          While loop example Write a 'c' program to find the sum of digits of a number using while loop e.g. num = 456 sum=4+5+6= 15 #include<stdio.h> #include<conio.h> main() { int num,sum; clrscr( ); printf("\nEnter the number :"); scanf("%d",&num); sum=0; while(num!=0) { sum=sum+num%10; num=num/10; } printf("\nSum of digits = %d",sum); getch();              }

Control Loop definition with types

  Control LOOP Loop are two type 1. Entry Control loop: - In which condition is checked at the entry point for the execution of the loop. For and while loop comes in this category 2.Exit control loop : - In which condition is checked at the last point for the execution of the loop. Do while loop is exit control loop. It execute at least once.         1. While Loop : - In while loop we first write the initial  value and                              then we checks the condition                             if the condition is true it enters the loop otherwise it comes out. In true condition it executes all the statement inside the curly braces. And then again checks. The condition this process repeats till the condition is true. Syntax Initialization; ...

Switch case Program with no of cases in C

  Switch case  Program   #include<stdio.h> #include<conio.h> void main() {          int i;          printf("enter the value ");          scanf("%d",&i);                    switch(i) {      case 1:            printf("sunday\n" );      break;    case 2:            printf("moday\n" );     break;     case 3:           printf("tus\n" );    break;    case 4:        printf("web\n" );    break;   default:       printf("No number in case\n"); } getch(); }

Switch case Syntax

              Case Control Statement (Switch case)  Syntax Case Control Statement Switch :- it works on choice which user enters. it remove the problem which created by the else if ladder and save the cup time Syntax:                         Switch(value)                         {                                              Case 1:                         ...

Syntax of else if in C

                        Syntax of else if   else if It remove the above problem but it has own problem it check all the condition until one condition is true. So it is time consuming. Syntax:-                                              If(condition1)                                                 {                          ...