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):")

Armstrong Numbers In C

We have Armstrong numbers like 0,1,153,371,9474 etc. We can specify it by some mathematical calculations and here we go:-)
153 has 3 digits and it means every digit has its power 3 and we have to add digits separately,
[1^3+5^3+3^3] and this answer matches with our number 153 wow so cool you know!
Like 153, We can also can do that with 371,9474 etc.

Here is the example of the code:

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    int d1,r,p,d2,x,t,i,k,sum=0;
    printf("enter a number--}");
    scanf("%d",&x);
    t=x;r=x;
    for(i=0;x>0;i++)
        {
            d1=x/10;
            d2=x%10;
            x=d1;

        }

         for(k=0;t>0;k++)
            {
                d1=t/10;
                d2=t%10;
                t=d1;
                p=pow(d2,i);
               //printf(" %d\t",p);
                sum=sum+p;

            }
            printf("\nsum is %d",sum);
if(r==sum)
    {
            printf("\n%d is an Armstrong number",r);
    }
else
    {
            printf("\n%d is not an armstrong number",r);
    }
    return 0;
}

Popular Posts