Tag: C program

  • Program to evaluate Graph equation y=x^n using C Language

    Program to evaluate Graph equation y=x^n using C Language

    This is the program to evaluate graph equation y=xn. This code works with non negative integers. The following code has been written and compiled in Dev c++. Code: #include<stdio.h> void main(){ int count,n; float x,y; printf(“enter the value of X and N \n”); scanf(“%f%d”,&x,&n); y=1.0; count=1; while(count<=n){ y=y*x; count++; } printf(“\nX = %.3f, N =…

  • Program to reverse a string in C Language

    The program below shows how you can reverse a string in c program. In this program I have used two arrays,one array is for the actual string to reverse and another array will keep the reversed string. The while function read the string from last to first and put each character in rev array. Code:…

  • Program to find GCD of two numbers in C language

    Program to find GCD of two numbers in C language

    The following program is to find the GCD or HCF of a number using C Language. GCD is the Greatest Common Divisor that divides a particular number. #include<stdio.h> void main(){ int a,b,i,j; printf(“\n****************************\nprogram to find GCD of 2 Numbers\n*****************************\n\n”); printf(“Enter two numbers: “); scanf(“%d%d”,&a,&b); printf(“Common Factors for %d and %d are: “,a,b); j=a>b?b:a; for(i=1;i<=j;i++){ if(a%i==0…

  • Program to convert a Character into ASCII value using C Language

    Program to convert a Character into ASCII value using C Language

    In C language, The integer value for a character is always it’s ASCII value. So If you want to print an ASCII value of a character in C then simply use %d to get the character’s ASCII integer value. Code: #include<stdio.h> void main(){ int c; char d; printf(“\n\n*****************Program to output ASCII code for an input********************\n”);…

  • Patterns Program Using C Language

    Patterns Program Using C Language

    The below article consists of different patterns that can be generated using C programs. Code-1: #include<stdio.h> void main(){ int i,j,k; int c=1,v=0; for(i=1;i<=9;i++){ if(i%2!=0){ for(j=i;j<=9;j++) { printf(” “); } for(k=1;k<=i;k++){ c++; if(c%2!=0){printf(“1 “); } else if(v==0) { printf(“1 “); v++;} else{ printf(“0 “);      } }    printf(“\n”);c=0;} } } OUTPUT:     CODE…

  • Program to Read an Input Keystroke using C Language

    **Note: To perform this I have used Dev c++ tool. It is checked and compiled. We can simple use getchar() to read the input character in C language Code: #include<stdio.h> void main(){ char c; printf(“\n\n*****************Program to Read an Input Keystroke******************\n\n”); printf(“Enter a Character: \n”); c=getchar(); printf(“Your Input Is: %c “,c); } OUTPUT: