Posts

Showing posts from April, 2022

|Display series and sum of 1+3+..+n in c| | display n number of series in c|

Image
C PROGRAM TO DISPLAY SERIES AND FIND SUM OF 1+3+5+....+n. Code: #include<stdio.h> int main() { int i,n,sum=1; printf("Enter any number n:"); scanf("%d",&n);     printf("1"); for(i=3;i<=n;i++) { printf("+ %d ",i); sum=sum+i; i++; } printf("\nSum is: %d", sum); } Explanation: First we are declaring the variables in integer datatype. Next is we are asking the user to enter a number so that we can find the sum of series and display it. We are storing the user entered data in the variable "n" . using a for loop to perform the sum of series Finally, displaying the result with the sum of series . OUTPUT: ORWDWlBMZLWeDLN0Q0ejOB4mO_QnraratLWJCyTt36SboL9lNq7kzQCDVIjbEPIHbN1T7oYXTKpSfRa5f7hMgLkUGx91skiesZbyPcaepxHlbfr/s653/Screenshot%20(254).png" style="margin-left: 1em; margin-right: 1em;">

|Sum of series in c|

Image
C PROGRAM TO FIND SUM OF SERIES Code: #include<stdio.h> int main() { int i,N; unsigned long sum; printf("Enter the value of N: "); scanf("%d",&N); sum=0; for(i=1;i<=N;i++) sum= sum+ (i*i); printf("Sum of the series is: %ld\n",sum); return 0; }  Explanation:              To find sum of series we get the required data from the user by using the statement "printf". The next step is we are storing the user given data in some variable called "N".   Then we are processing it using the above statements.  Then to get the desired output we are printing the exact statement to be displayed again using printf statement. outpu...

Displaying "*" symbol 20 times in c| |Display * in c|

Image
 C program to display the symbol "*" 20 times code: #include<stdio.h> int main() { int i, n=20; for(i=0; i<n; n--)    printf("\n*"); return 0; } note: You can also use any symbols in the place of "*".   Explanation: This is simple and easy to code and understand . The first step is to declare the variables. use a for loop to print the symbol "*" for 20 times The last step is to printf the "* one by one. Output: ...

|Displaying even numbers from 1 to 20 in c| | display even numbers in c|

Image
 C program to find even numbers from 1 to 20 code: #include<stdio.h> int main() { int i,n; printf(" Even numbers from 1 to 20\n"); for(i=1; i<=20; i++) { if(i%2 == 0) { printf("%d\n",i); } } return 0; } Explanation: The first step is to declare the variables Now we are using for loop to iterate untill 20 times next we are using if statement to check the condition   For example: if i=3 then the if condition will be like "if(3%2==0)" the condition is false because 3%2 is 0.06 so the condition will not be executed   after that it becomes i=4 then "if(4%2==0)" the condition is true so...

Display first 10 numbers in c

Image
 C program to display first 10 numbers code: #include<stdio.h> int main() { int i; printf("first 10 numbers"); for(i=1;i<=10;i++) { printf("\n%d",i); } return 0; } Explanation: Simple and easy program to understand Step 1: Declare the variable using a datatype (int, float, char) Step 2: Printing the statement to know what we are going to do. Step 3: Using a for loop to iterate it ,so that the first ten numbers get printed. Step 4: The 10 numbers should be printed so we are using printf statement to print all those "first 10 numbers" ,to printf the numbers one by one we use newline character"/n" . Output:

|Profit or Loss program in c| | calculate profit or loss in c|

Image
 C program to find profit and loss code: #include<stdio.h> int main() { int cp,sp,profit,loss; printf("enter the cost price:"); scanf("%d",&cp); printf("enter the selling price:"); scanf("%d",&sp); if(sp<cp) { /*loss*/ loss=cp-sp; printf("loss %d",loss); } else { /*profit*/     profit=sp-cp; printf("profit %d",profit); } return 0; } Explanation: Declaring the variable like "cp" for cost price "sp" for selling price and amount in integer datatype. Collecting d...

Time Table in c language |Time table in c|

Image
 C program to display time table code: #include<stdio.h> int main() { /*to display timetable*/ printf("Date\t|\tDate\t |\tSub1\t|\tSub2\t|\tSub3|\n13.10.21|\tMonday\t |\tTam\t|\tEng\t|\tmath|\n14.10.21|\tTuesday\t |\tVbc\t|\tDpca\t|\tCs-l|\n15.10.21|\tWednesday|\tCom\t|\tTam\t|\tEng |\n16.10.21|\tThursday |\tcs-t\t|\tDpca\t|\tVbc |\n17.10.21|\tFriday\t |\tcom\t|\tMath\t|\tEng |"); return 0; } Explanation: This program is not but displaying of timetable  with perfect alignment  In this I have used /*......*/ this is called as comment line This comment line helps in readability. Output:

Determinant of Matrix in C language

Image
 C program to find determinant of matrix code: #include <stdio.h> void main()    {   int arr1[10][10],i,j,n;   int det=0;        printf("\n\nCalculate the determinant of a 3 x 3 matrix :\n");        printf("-------------------------------------------------\n");  printf("Input elements in the first matrix :\n");        for(i=0;i<3;i++)         {             for(j=0;j<3;j++)             {            printf("element - [%d],[%d] : ",i,j);            scanf("%d",&arr1[i][j]);             }         }   printf("The matrix is :\n"); for(i=0;i<3;i++) ...

C program to find the value of ncr(combination) using function

Image
C program to find ncr code: #include <stdio.h>   int fact(int);   void main() {  int n,r,ncr;     printf("Enter a number n:");   scanf("%d",&n);     printf("Enter a number r:");   scanf("%d",&r); ncr=fact(n)/(fact(r)*fact(n-r));     printf("Value of %dC%d = %d\n",n,r,ncr); } int fact(int n) {     int i,f=1;     for(i=1;i<=n;i++)     {         f=f*i;     }     return f; } Explanation: In this program we are using "function" concept. To find ncr we first declare the variables We get the output from the user and store them. ncr formula is " ncr=fact(n)/(fact(r)*fact(n-r))" To print the result we are using printf stat...

VOWEL,CONSONANT,DIGIT AND SPACE in a string in C language

Image
  C PROGRAM TO FIND VOWEL,CONSONANT,DIGIT AND SPACE code: #include <stdio.h> int main()  {     char line[150];     int vowels, consonant, digit, space;     vowels = consonant = digit = space = 0;     printf("Enter a line of string: ");     fgets(line, sizeof(line), stdin);     for (int i = 0; line[i] != '\0'; ++i)  {         if (line[i] == 'a' || line[i] == 'e' || line[i] == 'i' ||             line[i] == 'o' || line[i] == 'u' || line[i] == 'A' ||             line[i] == 'E' || line[i] == 'I' || line[i] == 'O' ||             line[i] == 'U') {             ++vowels;         } else if ((line[i] >= 'a' && line[i] <= 'z') || (line[i] >= 'A' && line[i] <= 'Z')) { ...

Find Fibonacci series in C language

Image
  C program to find Fibonacci series Code: #include <stdio.h> int fibo(int num); int main() {     int num;     int fibonacci;     printf("Enter any number to find nth fibonacci term: ");     scanf("%d", &num);     fibonacci = fibo(num);      printf("%d fibonacci term is %d", num, fibonacci);     return 0; } int fibo(int num)  {     if(num == 0)               return 0;     else if(num == 1)          return 1;     else          return fibo(num-1) + fibo(num-2);  } Explanation: What is Fibonacci series? A series of numbers in which each number (Fibonacci number) is the sum ...

Area of Circle | area of circle using c|

Image
C PROGRAM TO FIND AREA OF CIRCLE google-site-verification: google92f1512c4881b7f9.html Code: #include <stdio.h> int main() {    int area_of_circle,rad;    float PI_VALUE=3.14;    printf("Enter radius of circle: ");    scanf("%d",&rad);   area_of_circle = PI_VALUE *rad*rad;    printf("Area of circle is: %d",area_of_circle);    return(0); } Explanation: We are declaring the variable in integer data type. To find area of circle we need the value of Pi . So, we declare the value of Pi as "PI_VALUE=3.14" in float datatyp e . We getting the radius of the circle from the user. And storing the value of radius in "rad" . We declare it in float datatype because it a have value like point "...