Posts

Showing posts from May, 2021

Write a C program to calculate and print the value of nPr.

  #include <stdio.h> int   fact ( int ); void   main () {      int   n , r , nPr ;      printf ( "Enter a number n \n " );      scanf ( "%d" , & n );      printf ( "Enter a number r \n " );      scanf ( "%d" ,& r );      nPr = fact ( n )/ fact ( n - r );      printf ( "The value of %dP%d = %d \n " , n , r , nPr ); } int   fact ( int   n ) {      int   i , f = 1 ;      for  ( int   i   =  1 ;  i  <=  n ;  i ++)     {          f = f * i ;     }      return   f ;    } after that you can enter n and r then run the code and see the results.

Check whether a character Vowel or Consonant

  #include   <stdio.h> int   main () {      char   x ;      int   lowercase_vowel ,  uppercase_vowel ;      printf ( "Enter a letter: \n " );      scanf ( "%c" , & x );      lowercase_vowel  = ( x  ==  'a'  ||  x  ==  'e'  ||  x  ==  'i'  ||  x  ==  'o'  ||  x  ==  'u' );      uppercase_vowel  = ( x  ==  'A'  ||  x  ==  'E'  ||  x  ==  'I'  ||  x  ==  'O'  ||  x  ==  'U' );      if  ( lowercase_vowel  ||  uppercase_vowel )     {          printf ( "The character is a Vowel \n " );     } ...

Write C program to check whether a number is even or odd

  #include <stdio.h> int   main () {      int   a ;      printf ( "Enter the number which you want to check if it it is even or odd \n " );      scanf ( "%d" , & a );      if  ( a  %  2  ==  0 )     {          printf ( "The entered %d integer is a Even number" ,  a );     }      else {          printf ( "The entered %d integer is an Odd number" ,  a );     }      return   0 ;      } Now if you enter 7 then the output will be Odd and if you enter 8 then the output will be Even Hope this will help you. Happy...

Print Star pattern by using C language

Image
Print Star pattern    #include <stdio.h> void   StarPattern ( int   rows ) {      for  ( int   i  =  0 ;  i  <  rows ;  i ++)     {          for  ( int   j  =  0 ;  j  <=  i ;  j ++)         {            printf ( "*" );         }          printf ( " \n " );              }      } int   main () {      int   rows ;      printf ( "How many star patterns do you want? \n " );      scanf ( "%d" , & rows );      StarPattern ( rows ); ...

Addition, Subtraction, Multiplication, Division with C language

Image
 #include<stdio.h> int main() {     int a, b;     /*a= 4;     b= 2;*/     printf("Enter the values you want to calculate\n");     scanf("%d %d", &a , &b);     printf("a+b = %d\n", a+b);          printf("a-b = %d\n", a-b);     printf("a*b = %d\n", a*b);     printf("a/b = %d\n", a/b);     return 0; } There is two options available for you, you simply put the values of the variables in the first line(that was just comment out there you can see the code & in the picture) or you just simply use the "scanf" to get input from user. In the division output sometimes you will get '0' as result because here we used "int" not "float" . I wish you get help from this, thank you.

How to add to integers in C programming

Image
 #include<stdio.h> int main(int argc, char *argv[]) {     int a, b;     printf("Enter number a\n");     scanf("%d", &a);     printf("Enter number b\n");     scanf("%d", &b);     printf("The sum is %d\n", a+b);     return 0; } Now give two integers as user input and press "Enter" and check the results. If you have any doubt comment down below.

Write a C programme to find the given integer positive or negative

Image
 #include<stdio.h> int main() {      int a;     scanf("%d",&a);      if(a>=1)      {         printf("Positive Integer\n");      }      else      {         printf("Negative Integer\n");      }          return 0; } After writing the code, now compile it and run it your IDE, give some user input and check the results.

Access denied in VS code for gcc while doing C programming

Image
  Hi guys the problem I am going to discuss in this blog is about some problem that you may face while doing C programme in your VS code. There are various methods to install VS code and MinGW(C compiler) but when you use them to run a code it may show you some error in output or in VS code terminal. But if you think your installation process is wrong, wait that may be not the reason, it's because of your system's anti virus that is blocking your    VS code to get access of your  MinGW's bin folder. This problem mostly seen when you buy a new Laptop or PC & they give you a trial of anti virus software (McAfee). Solution :  All you need to do is when you gonna run a programme in your system simply 1>Open your McAfee anti virus application 2>Now find the settings option then click on it and then click on "Real Time Scanning" 3>Now last step is click on the "Turn Off" button and turn it off as long as you want. With these simple steps you can e...

C program to find the greatest of three numbers with user input.

Image
#include<stdio.h> int main() {     int num1,num2,num3;     printf("\nEnter value of num1,num2,num3:");     scanf("%d %d %d", &num1, &num2 ,&num3);     if((num1>num2)&&(num1>num3)){              printf("The greatest number is num1\n");     }          else if((num2>num3)&&(num2>num1)){                   printf("The greatest number is num2\n");     }else{             printf("The greatest number is num3\n");     }                   return 0; } after that when you run this code into your Vs code terminal, you have to give some input to your program then press "Enter" and you will see the output in your terminal.