Skip to main content

Featured

Data of Employees using Structure

There is a structure called employee that holds information like employee code, name, date of joining. That is a program that creates an array of the structure and enters some data. Then ask the user to enter current date. After that Display the names of those employees whose tenure is 3 or more than 3 years according to the given current date. #include<stdio.h> #include<stdlib.h> struct emp{     int code,date;     char name[16]; }; int main() {      struct emp e[20];      int x,i,j,cdate,res;      printf("How many employee are there?");      scanf("%d",&x);      for(i=0;i<x;i++)      {          printf("Enter Employee code:");//int          scanf("%d",&e[i].code);          printf("Enter employee name:");          scanf("%s",e[i].name);          printf("Enter date of joining(yyyymmdd):");          scanf("%d",&e[i].date);      }      printf("Enter current date(yyyymmdd):")

Simple calculator in C

 Hello, I've made simple calculator using C language and It can perform basic commands of calculator like Addition, Subtraction etc on 2 numbers.

Here is its code:-)

#include<stdio.h>

#include<stdlib.h>

int main()

{

    int num1,num2;

    char ch;

    float r,p;

    printf("This is calculator\n");

    printf("for sum type + sign\n");

    printf("for substracation type - sign\n");

    printf("for multipllication type * sign\n");

    printf("for devision type / sign\n");

    scanf("%c",&ch);


    printf("enter two numbers");

    scanf("%d%d",&num1,&num2);

    switch(ch)

        {

            case '+':

                printf("sum is %d",num1+num2);

                break;

            case '-':

                printf("sub. is %d",num1-num2);

                break;

            case '*':

                printf("multi. is %d",num1*num2);

                break;

            case '/':

                r = num1/num2;

                printf("devision is %f",r);

                break;

            default:

                printf("invalid input");


        }


    return 0;


}


Popular Posts