Skip to main content

Posts

Showing posts from December, 2020

Write a C program to calculate profit or loss.

 Que : Write a C program to calculate profit or loss. Ans :  #include <stdio.h> int main()   {       int CP,SP,PL;   //( for understanding pl= profilt and loss)     printf("Enter Cost Price: ");       scanf("%d", &CP);       printf("Enter Selling Price: ");       scanf("%d", &SP);              if(SP>CP)      {           PL= SP-CP;           printf("\nYou are in profit and the  amount is : %d\n",PL);       }       else  if(CP>SP)     {           PL = CP-SP;           printf("\nYou get loss of amount : %d\n", PL);       }       else       {   ...

Write a C program to check whether a person is eligible for voting or not?

 Que :  C program to check whether a person is eligible for voting or               not? Ans :  #include <stdio.h>   int main() {    int a;    printf("Enter Your age : ");    scanf("%d",&a);    if (a >=18)    {        printf("you are  eligible for voting  ");    }    else    {        printf("You are not  eligible for voting ");    }    return 0; }

Write a C program to find maximum between two numbers.

 Que.  Write a C program to find maximum between two numbers. Ans.  #include<stdio.h> int main() { int a,b; printf("Enter the two numbers : "); scanf("%d %d",&a,&b); if(a>b) { printf("the biggest number is %d :"); } else { printf("the Smallest number is %d and biggest is second  One :) "); } return 0;   }

Write a C program to find minimum between three numbers.

 Que : Write a C program to find minimum between three numbers. Ans : #include<stdio.h> int main() { int a,b,c; printf("Enter the three numbers : "); scanf("%d %d %d",&a,&b,&c); if(a<b) { if(a<c) printf("the smaller number is :%d",a); else printf("the smaller number is :%d",c); } else { if(b<c) printf("the smaller number is :%d",b); else printf("the smaller number is :%d",c); }          return 0;   }

Write a C Program to find largest number among three numbers.

Que : Program to find largest number among three               numbers. Ans : #include<stdio.h> int main() { int a,b,c; printf("Enter the three numbers : "); scanf("%d %d %d",&a,&b,&c); if(a>b) { if(a>c) printf("the bigger number is :%d",a); else printf("the bigger number is :%d",c); } else { if(b>c) printf("the bigger number is :%d",b); else printf("the bigger number is :%d",c); }          return 0;   }

Write a C program to find even or odd number

 Que : write a c program to find even or odd number Ans: #include <stdio.h>   int main() {    int a;    printf("Enter a number : ");    scanf("%d",&a);    if ( a%2==0 )    {        printf("the number is even");    }    else    {        printf("the number is odd ");    }    return 0; } ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Write a C program to perform if & else.

Write a C program to demonstrate  if & else. Ans: #include <stdio.h>   int main() {    int a,b;    printf("Enter the two number : ");    scanf("%d %d",&a,&b);    if (a == b)    {        printf("a and b are equal");    }    else    {        printf("a and b are not equal");    } }

Write a C program to demonstrate While, Do while & For.

  Que :Write a C program using While. Ans : #include<stdio.h> int main() { int i=1; while(i<5) { printf("\nSengra ji "); i++; } return 0; }