Skip to main content

Posts

Showing posts from May, 2022

Example of arithmetic operator in c

  #include <stdio.h> int main() { int a=40,b=20, add,sub,mul,div,mod; add = a+b; sub = a-b; mul = a*b; div = a/b; mod = a%b; printf("Addition of a, b is : %d\n", add); printf("Subtraction of a, b is : %d\n", sub); printf("Multiplication of a, b is : %d\n", mul); printf("Division of a, b is : %d\n", div); printf("Modulus of a, b is : %d\n", mod); }

Example of ASSIGNMENT OPERATORS IN C

  // to divide #include<stdio.h> int main() { int a =12; printf("%d\n",a/=2);                                 // it simply divide a by 2 return 0; } // to add #include<stdio.h> int main() { int a =12; printf("%d\n",a+=1);                               // it simply add 1 to a return 0; } // to subtract #include<stdio.h> int main() { int a =12; printf("%d\n",a-=5);                            // it simply subtract 5 from a return 0; } // to multiply #include<stdio.h> int main() { int a =12; printf("%d\n",a*=3);                             // it simply multiply a by 3 return 0; } // if i combime all error occur #include<stdio.h> int main() { int a =12; printf("%d\n",a+=1);                              // it simply add 1 to a printf("%d\n",a-=5);                              // it simply subtract 5 from a printf("%d\n",a*=3);                             // it simply multiply a by 3 printf(&qu

1-D & 2-D array

 #include<stdio.h> int main() {     int marks[]={25,28,27};     marks[3]=29;     printf("The of student 1 is:-%d\n",marks[0]);     printf("The of student 2 is:-%d\n",marks[1]);     printf("The of student 3 is:-%d\n",marks[2]);     printf("The of student 4 is:-%d\n",marks[3]);     printf("The average of student marks is %d:-",(marks[0]+marks[1]+marks[2]+marks[3])/4);     return 0; }     //Another code  2-D array      #include<stdio.h> int main() {     int marks[2][5]={{95,93,97,87,94},    here 2 represents no of rows & 5 s represents no of column.                      {87,89,88,85,83}};     for (int i = 0; i < 2; i++)     {         for (int j = 0; j < 5; j++)         {             printf("The value of %d, %d value of the array is %d\n",i,j,marks[i][j]);         }     }     return 0; }     // Another code     #include<stdio.h> int main() {     int marks[5];                    //declare without initial

program to check whether a number is prime number or not.

#include<stdio.h> int main() {     int a,i,j;     printf("Enter a range of numbers to check prime number between them\n");     printf("Enter the first number\n");     scanf("%d",&i);     printf("Enter the second number\n");     scanf("%d",&j);      for(a=i;a<=j;a++)      {     if (a%1==0&&a%a==0&&a%2!=0&&a%3!=0&&a%4!=0&&a%5!=0&&a%6!=0&&a%7!=0&&a%8!=0&&a%9!=0)     {         printf("%d is prime number\n",a);     }     else     printf("%d is not a prime number\n",a);      } } there is mistake in it find it out.