Thursday, April 25, 2013

Function: Use of function

Write a program to show the use of function 


#include<stdio.h>
main()
{
int a,b,c;
printf("\n\tIT'S A PROGRAM  TO  SHOW THE USE OF FUNCTION\n");
printf("\nEnter the value of a:");
scanf("%d",&a);
printf("\nEnter the value of b:");
scanf("%d",&b);
c=rose(a,b);
printf("\nMultiplication of %d and %d is:",a,b);
printf("%d",c);
}

rose(x,y,p)
int p,x,y;
{
p =x*y;
return (p);
}

Riverse an integer number

Write a program in c which will reverse an integer number.After print the output make the sum of all digits. 



#include<stdio.h>
main()
{
int num, reverse, sum=0;
printf("\n\tIT'S A PROGRAM TO REVERSE AN INTEGER NUMBER\n");
printf("\n\nEnter the number for reverse:");
scanf("%d", &num);
printf("\nAfter Reverse the number is: ");
while(num!= 0)
{
  reverse= num%10;
  num /=10;
  sum += reverse;
  printf("%d", reverse);
}
printf("\n\nSum of all Digits: %d", sum);

getch();
return 0;
}

Perfect number:Perfect number in c

Write a program in c which will check a number perfect or not 



#include<conio.h>
#include<stdio.h>
main()
{
    int num,i=1,sum=0,j;
    printf("\n\tIT'S A PROGRAM TO CHACK A NUMBER PERFECT OR NOT");
    printf("\n\nEnter the number:");
    scanf("%d",&num);
    while(i<num)
    {
        for(j=1;j<=i;j++)
        if(num%i==0)
        sum=sum+i;
        i++;
    }
    if(sum==num)
    {
        printf("\n%d is a perfect number\n",num);
    }
    else
    {
        printf("\n%d is not a perfect number\n",num);
    }
    return 0;
}

Factorial in c

Write a program in c to find the factorial of a number 



#include<stdio.h>
#include<conio.h>
main()
{
    int i,sum=1,num;
    printf("\n\tIT'S A PROGRAM TO FIND THE FACTORIAL OF A NUMBER:");
    printf("\n\nEnter the number:");
    scanf("%d",&num);
    for(i=1;i<=num;i++)
    {
        sum*=i;

    }
    printf("\nFactorial value of %d is:",num);
    printf("%d\n",sum);
    }

Switch Programming: Switch programming in C

Write a program which will find the division from a average grade obtained by a student by using switch case in C 




#include<stdio.h>
#include<conio.h>
main()
{
    char ch;
    scanf("%c",&ch);
    switch (ch)
    {
        case 'A':
        printf("1st division");
        break;
        case 'B':
        printf("2nd division");
        break;
        case'C':
        printf("3rd division");
        break;
    }
    return 0;
}