Skip to main content

Posts

NESTED IF ELSE

Nested If Else #include < stdio.h > void main() {   int marks;   printf("Enter your marks : ");   scanf("%d",&marks);   if(marks>100) /*marks greater than 100*/     printf("Not valid marks");   else if(marks>=80) /*marks between 80 & 99*/     printf("your grade is A");   else if(marks >=70) /*marks between 70 & 79*/     printf("your grade is B");   else if(marks>=50) /*marks between 50 & 69*/     printf("your grade is C");   else if(marks>=35) /*marks between 35 & 49*/     printf("your grade is D");   else /*marks less than 35*/     printf("your grade is E"); }

CALCULATE PERCENTAGE

Calculate percentage #include < stdio.h > void main() { int s1, s2, s3, s4, s5, sum, total = 500; float per; printf("\nEnter marks of 5 subjects : "); scanf("%d %d %d %d %d", &s1, &s2, &s3, &s4, &s5); sum = s1 + s2 + s3 + s4 + s5; printf("\nSum : %d", sum); per = (sum * 100)/500; /* percentage formula*/ printf("\nPercentage : %f", per); }

CALCULATE GROSS SALARY

Calculate Gross salary #include < stdio.h > void main() { int gross_salary, basic, da, ta; printf("Enter basic salary : "); scanf("%d", &basic); da = (10 * basic)/100; ta = (12 * basic)/100; gross_salary = basic + da + ta; printf("\nGross salary : %d",gross_salary); }

PRINT INTEGER

Print Integer #include < stdio.h > int main() {   int a;   printf("Enter an integer\n");   scanf("%d", &a);   //takes an integer from user   printf("Integer that you have entered is %d\n", a);   return 0; }

SIMPLE INTEREST

Simple interest #include < stdio.h > void main() { int amount, rate, time, ans; printf("\nEnter Principal Amount : "); scanf("%d", &amount); printf("\nEnter Rate of Interest : "); scanf("%d", &rate); printf("\nEnter Period of Time : "); scanf("%d", &time); ans = (amount * rate * time)/100; /*Simple interest formula*/ printf("\nSimple Interest : %d",ans); }

FACTORIAL USING RECURSION

Factorial using recursion #include < stdio.h > long factorial(int); int main() {   int n;   long f;   printf("Enter an integer to find factorial\n");   scanf("%d", &n);   if (n < 0)   printf("Negative integers are not allowed.\n");   else   {   f = factorial(n);   printf("%d! = %ld\n", n, f);   }   return 0; } long factorial(int n) {   if (n == 0)   return 1;   else   return(n * factorial(n-1));   /*recursive call to factorial function*/ }

FACTORIAL USING FUNCTION

Factorial using function #include < stdio.h > long factorial(int); int main() {   int number;   long fact = 1;   printf("Enter a number to calculate it's factorial\n");   scanf("%d", &number);   printf("%d! = %ld\n", number, factorial(number));   return 0; } long factorial(int n) {   int c;   long result = 1;   for (c = 1; c <= n; c++)   result = result * c;  /*multiplying result by 1,2,3...n */   return result; }