The if statement controls conditional branching.The body of an if statement is executed if the value of the expression is nonzero.The if statement allows you to control if a program enters a section of code or nor based on whether a given condition is true or false.One of the important function of the if statement is that it allows the program to select an action based upon the user's input.For example we can check user entered password by using if statement,and decide whether a user is allowed access to the program.
Syntax ...
Tuesday, June 28, 2011
C PROGRAM TO REVERSE A NUMBER USING WHILE LOOP
/*Program to reverse a number using while loop*/#include<stdio.h>void main(){long int number,reverse,n;clrscr();printf("Enter the number");scanf("%ld",&number);reverse=0;while(number!=0){n=number%10;reverse=reverse*10+n;number=number/10;}printf("The reverse number=%ld\n",reverse);getch( ...
TO FIND THE SUM OF DIGITS IN A FIVE DIGIT NUMBER
#include<stdio.h>
void main(){int digit_1,digit_2,digit_3,digit_4,digit_5,sum,number,n;printf("Enter a five digit number");scanf("%d",&number);n=number;digit_1=n%10;n=n/10;digit_2=n%10;n=n/10;digit_3=n%10;n=n/10;digit_4=n%10;n=n/10;digit_5=n;sum=digit_1+digit_2+digit_3+digit_4+digit_5;printf("sum of digits=%d\n",sum);getch() ...
Subscribe to:
Posts (Atom)