Skip to main content

Posts

Showing posts from August, 2019

How to use array.

→ This program will help you to learn how to implement an array in C. #include<stdio.h> int main() {   int arr[5]; //declaration of an array with maximum five values   int i;   printf("Enter five numbers:");   for(i=0;i<5;i++)   {      scanf("%d",&arr[i]);  //This line will take input in array from index zero to five i.e arr[0] to arr[4]   }   printf("Your numbers are:");   for(i=0;i<5;i++)   {     printf("%d  ",arr[i]);   }   return 0; } Output: Enter five numbers:5 6 9 8 12 Your numbers are:5  6  9  8  12

A simple calculator program.

→ A simple calculator using C language. In this, you can add, multiply, divide and subtract any two number. #include<stdio.h> int main() {    float a,b,c;    char d;    printf("Enter:");    scanf("%f  %c %f",&a,&d,&b);    if(d=='+')    {     c=a+b;     printf("%.2f",c);    }    else if(d=='-')    {     c=a-b;     printf("%.2f",c);    }    else if(d=='*')    {     c=a*b;     printf("%.2f",c);    }    else if(d=='/')    {     c=a/b;     printf("%.2f",c);    } } Output: Enter:  9/4              2.25

C Program to take input from the user.

→ Program to take input from the user- integer, char, string, decimal, and to print all values. #include<stdio.h> int main() {   int a;   char b;   char c[10];   float d;   printf("Enter interger value:");   scanf("%d",&a);   printf("\nEnter a character:");   scanf(" %c",&b);   printf("\nEnter a name:");   scanf("%s",&c);   printf("\nEnter decimal value:");   scanf("%f",&d);   printf("\nInterger value is %d ",a);   printf("\nYour Character is %c ",b);   printf("\nGiven name is %s ",c);   printf("\nDecimal value is %f ",d);   return 0; }