বৃহস্পতিবার, ২ জানুয়ারী, ২০২০

Basic C Programming


#include<stdio.h>

int main()
{

    int i,n,min=0,secmin,loc=1,seclocation;

    printf("Give the number :");
    scanf("%d",&n);
    int num[n];
    for(i=1;i<=n;i++)
    {
    scanf("%d",&num[n]);
    }
    min=num[0];
    for(i=1;i<=n;i++)
    {
        if(num[i]<min)
        {
          secmin=min;
          seclocation=loc;
          min=num[i];
          loc=i+1;
        }


    }
    printf("That is %d,%d\n",seclocation,secmin);


}
 



#include<stdio.h>

int main()
{
    printf("Studytonight - Best place to learn");

    double a, b, c;

    printf("Enter 3 numbers:\n");
    scanf("%lf%lf%lf", &a, &b, &c);  //lf is a format specifier to take double as input

    if(a >= b && a >= c)
    {
        if(b >= c)
        {
            printf("\n\n%.2lf is the 2nd largest number\n", b);
        }
        else
        {
            printf("\n\n%.2lf is the 2nd largest number\n", c);
        }
    }
    else if(b >= a && b >= c)
    {
        if(a >= c)
        {
            printf("\n\n%.2lf is the 2nd largest number\n",a);
        }
        else
        {
            printf("\n\n%.2lf is the 2nd largest number\n",c);
        }
    }

    else if(a >= b)
    {
        printf("\n\n%.2lf is the 2nd largest number\n", a);
    }else
    {
        printf("\n\n%.2lf is the 2nd largest number\n", b);
    }

    printf("\n\n\t\t\tCoding is Fun !\n\n\n");
    return 0;
}




#include<stdio.h>>


int main()
{
int i=0,d,n;
printf("Give The number You want to sum :\n");
scanf("%d",&n);
for (i=0;i<=n;i++)
{
d=d+i;
printf("\nNext Number are :%d",i);

}

printf("\nTotal of all are :%d",d);
}

===========================

#include <stdio.h>
void main()
{
int i,n,sum=0;
float avg;
printf("Input the 10 numbers : \n");
for (i=1;i<=10;i++)
{
printf("Number-%d :",i);

scanf("%d",&n);
sum +=n;
}
avg=sum/10.0;
printf("The sum of 10 no is : %d\nThe Average is : %f\n",sum,avg);

}

=========================

#include <stdio.h>
void main()
{
int i,ctr;
printf("Input number of terms : ");
scanf("%d", &ctr);
for(i=1;i<=ctr;i++)
{
printf("Number is : %d and cube of the %d is :%d \n",i,i, (i*i*i));
}
}

=======================

#include <stdio.h>
void main()
{
   int i,n,sum=0;

   printf("Input number of terms : ");
   scanf("%d",&n);
   printf("\nThe odd numbers are :");
   for(i=1;i<=n;i++)
   {
     printf("%d ",2*i-1);
     sum+=2*i-1;
   }
   printf("\nThe Sum of odd Natural Number upto %d terms : %d \n",n,sum);
}
===================================


#include <stdio.h>

void main()
{
   int i,n,sum=0;

   printf("Input number of terms : ");
   scanf("%d",&n);
   printf("\nThe even numbers are :");
   for(i=1;i<=n;i++)
   {
     printf("%d ",2*i);
     sum+=2*i;
   }
   printf("\nThe Sum of even Natural Number upto %d terms : %d \n",n,sum);
}

====================================

#include<stdio.h>>


int main()
{
 int i=0,d=1,n;
 char t;
 printf("Give The number You want to sum :\n");
 scanf("%d",&n);
for (i=0;i<=n;i++)
{
    d=d+4*i;
    printf("%d",d);
t=t*(-1);
if (i<n)
      {
          printf("+");

      }
}
}
===============================


#include<stdio.h>>


int main()
{
 int num[5],i,n,sum=0;
 char t;
 printf("Give The number You want to sum :");
 scanf("%d",&n);

 for (i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
for (i=0;i<n;i++)
{
sum=sum+num[i];

}
printf("Number are :%d",sum);
}
=================================

#include<stdio.h>>

int main()
{
 int num[5],i,n;
 char t;
 printf("Give The number You want to sum :");
 scanf("%d",&n);

 for (i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
  int  max=num[0];
for (i=0;i<n;i++)
{

    if (max<num[i])
max=num[i];

}
printf("Number are :%d",max);
}

=============================

#include <stdio.h>

void main()
{
  int n,i;
  long sum=0;
  long int t=1;
  printf("Input the number of terms : ");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
  {
     printf("%ld  ",t);
      if (i<n)
      {
          printf("+ ");

      }
     sum=sum+t;
     t=(t*10)+1;
  }
  printf("\nThe Sum is : %ld\n",sum);
}

=============================


#include<stdio.h>>


int main()
{
 int i=0,d=1,n;
 char t;
 printf("Give The number You want to sum :\n");
 scanf("%d",&n);
for (i=1;i<=n;i++)
{

    printf("\n%d",d);
d=d+4;

}
}

==============================


#include<stdio.h>>


int main()
{
 int i=0,d=1,n;
 char t;
 printf("Give The number You want to sum :\n");
 scanf("%d",&n);
for (i=1;i<=n;i++)
{
d=i;
    printf("%d",d);
t=t*(-1);
if (i<n)
{
    printf("%c",t);
}

}
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন