Sunday, September 29, 2019

Recursive function --sum of series

1^1+2^2+3^3________+n^n
Recursion
Sum of series n to power n up to n terms



#include <stdio.h>
#include <stdlib.h>



npn(int x)
{ int i,r;

r=1;
for(i=1;i<=x;i++)
{  r=r*x;  }
return r;
}

sn(int n)
{ if(n==1)
return 1;
else{ return sn(n-1) +npn(n);}


}



main()
{ int b,k=1;
while(k==1)
{ system("cls");
printf("you are going to find sum series of n to power n,\nup to n terms \nenter no.of terms \n");
scanf("%d",&b);
printf("%d",sn(b));
printf("\n\n1.try once again\n2.exit\nchoose any option....");
scanf("%d",&k);
}

}

Monday, September 16, 2019

2nd sheet 3rd question

#include<stdio.h>
main()
{  
float sales,salary;
printf("enter the total sales of last week in dollors  \n");
scanf("%f",&sales);
salary=200+(sales*9)/100;
printf("total salary in dolors = %f",salary);




}

2nd assignment sheet 2nd question

#include<stdio.h>
main()
{    
int account;
float begbal,totchar,tocred,allcred ,newbal   ;
printf("enter your account no.\n");
scanf("%d",&account);
printf("enter your begning balance");
scanf("%f",&begbal);
printf("enter total charges");
scanf("%f",&totchar);
printf("enter total credit \n");
scanf("%f",&tocred);
printf("enter allowed credit limit");
scanf("%f",&allcred);
newbal=begbal+totchar-tocred;
printf("account:%d\n credit limit:\n balance:\n ",account,allcred,newbal);
if(newbal>=allcred)
{printf("credit limit exeeded");}
else{ printf("credit limit not exeeded");}
}

Second assignment sheet 1st question

#include<stdio.h>
main()

{int a,b;
printf("enter a and b\n");
scanf("%d%d",&a,&b);
if(a<b)
{ printf("%d is less than %d\n",a,b);}
else if (a=b)
{printf("%d is equal to %d\n",a,b);}
else{ printf("%d is greater than %b\n",a,b);}
}    




Friday, September 13, 2019

Power of a to b (@function call)

#include <stdio.h>
int power(int,int);
int r;
main()
{  
int a,b;
printf("you are finding a power b\n");

printf("enter in form of ' a space b' \n");
scanf("%d%d",&a,&b);
power(a,b);
printf("%d",r);
}

power(int a,int b)
{ int i;

r=1;
for(i=1;i<=b;i++)
{  r=r*a;  }
return r;
}

Some amazing codes --print digits digitaly

#include <stdio.h>
main()
{  
int a,b,i,s,l;
printf("in form of a b \n");

printf("enter starting.,maximum size.\n");
scanf("%d%d",&s,&l);
for(i=s;i<=l;i++)
{  a=i,b=i;
  one(a,b);
  two(a,b);three(a,b);four(a,b);five(a,b);six(a,b);seven(a,b);eight(a,b);nine(a,b);
}

}

one(a,b)
{
vline (a,b);
printf("\n \n \n");

}

two(a,b)
{  hline(a,b);vline(a+b,b);
hline(a,b); vline(a,b);hline(a,b);
printf("\n \n \n");
}

three(a,b)
{  hline(a,b);vline(b+a,b);hline(a,b);
vline(a+b,b);hline(a,b);
printf("\n \n \n");
}

four(a,b)
{ dobvline(a,b);hline(a,b);vline(a+b,b); printf("\n \n \n");
}
five(a,b){
hline(a,b);vline(a,b);hline(a,b);  vline(a+b,b);  hline(a,b); printf("\n \n \n");
}
six(a,b){ hline(a,b);vline(a,b);hline(a,b);dobvline(a,b); hline(a,b); printf("\n \n \n");
}
seven(a,b){hline(a,b); vline(a+b,b*2); printf("\n \n \n");}
eight(a,b){   hline(a,b);dobvline(a,b);hline(a,b);dobvline(a,b);hline(a,b); printf("\n \n \n");
  }
nine(a,b){   hline(a,b); dobvline(a,b);
hline(a,b); vline(a+b,b);hline(a,b); printf("\n \n \n");

}






hline(int a,int b)
{ int i;


for(i=1;i<=a;i++)
{ printf(" ");}
for(i=1;i<=b;i++)

{  
 printf("-");  }
 printf("\n");

}

vline(int a,int b)
{ int i,j;
for (i=1;i<=b/2;i++)
{   for(j=1;j<=a;j++)
   {
    printf(" ");
   }
 printf("| \n");}
}
  dobvline(int s,int l)
{
int i,j;
for(i=1;i<=l/2;i++)
{  for(j=1;j<=s;j++)
 {printf(" ");}
 printf("|");
 for(j=1;j<l;j++)
 {printf(" ");}
 printf("|");
 printf("\n");
 }

}

Wednesday, September 11, 2019

Illusion pattern

#include <stdio.h>
#include <stdlib.h>
main()
{
int i,j,k,n;






for(i=1;i<=5;i++)
{  for(j=1;j<=24-i;j++)
 {
  printf("a");
 }
 for(k=1;k<=2*(i);k++)
 {
  printf("p");
 }
 for(j=1;j<=24-i;j++)
 {
  printf("a");
 }
 printf("\n");
 }


for(i=5;i>=1;i--)
{  for(j=1;j<=14-i;j++)
 {
  printf("a");
 }
 for(k=1;k<=2*i+20;k++)
 {
  printf("p");
 }
  for(j=1;j<=14-i;j++)
 {
  printf("a");
 }
 printf("\n");
 }



for(i=1;i<=5;i++)
{  for(j=1;j<=14-i;j++)
 {
  printf("a");
 }
 for(k=1;k<=2*i+20;k++)
 {
  printf("p");
 }
 for(j=1;j<=14-i;j++)
 {
  printf("a");
 }
 printf("\n");
 }


for(i=5;i>=0;i--)
{  for(j=1;j<=24-i;j++)
 {
  printf("a");
 }
 for(k=1;k<=2*i;k++)
 {
  printf("p");
 }
  for(j=1;j<=24-i;j++)
 {
  printf("a");
 }
 printf("\n");
 }
 
 
}
 

 

 


 
 
 

Monday, September 9, 2019

Sum of five digit no. Sheet 1 sem 1

#include<stdio.h>
 main()
{
int N,sum,i;
printf("enter the five digit no...\n");
scanf("%d",&N);
sum=0;
for(i=1;i<=5;i++)
{
sum=sum+N%10;
N=N/10;

}
printf("sum of digit :%d\n",sum);
return 0;
}

Reverse three digit no. Sheet 1 ,sem 1

#include <stdio.h>
main()
{   int N,a,b,c,RN;
printf("enter a three digit no.\n");
scanf("%d",&N);
a=N%10;
N=N/10;
b=N%10;
N=N/10;
c=N;
RN=100*a+10*b+c;
printf("no.after reversing became %d",RN);
}

Product of floating pt.no. sheet 1 sem 1

#include <stdio.h>
main()
{  float a,b,prod;
printf("enter the two number 1...\n");
scanf("%f",&a);
printf("enter the no.2\n");
scanf("%f",&b);
prod=a*b;
printf("%f is product of %f and %f",prod,a,b);
}

Sunday, September 8, 2019

Star plus arrow

#include <stdio.h>
main()
{
int i,j,k;
for(i=1;i<=5;i++)
{  for(j=1;j<=24-i;j++)
 {
  printf(" ");
 }
 for(k=1;k<=2*i;k++)
 {
  printf(".");
 }
 printf("\n");
 }


for(i=5;i>=1;i--)
{  for(j=1;j<=14-i;j++)
 {
  printf(" ");
 }
 for(k=1;k<=2*i+20;k++)
 {
  printf(".");
 }
 printf("\n");
 }



for(i=1;i<=5;i++)
{  for(j=1;j<=14-i;j++)
 {
  printf(" ");
 }
 for(k=1;k<=2*i+20;k++)
 {
  printf(".");
 }
 printf("\n");
 }


for(i=5;i>=0;i--)
{  for(j=1;j<=24-i;j++)
 {
  printf(" ");
 }
 for(k=1;k<=2*i;k++)
 {
  printf(".");
 }
 printf("\n");
 }
 

printf("\n\n\n");


   for(i=1;i<=10;i++)
{  for(j=1;j<=(24-(i/2));j++)
 {
  printf(" ");
 }
 for(k=1;k<=i;k++)
 {
  printf("*");
 }
 printf("\n");
 }

 for(i=1;i<=200;i++)
 {
  for(j=1;j<=23;j++)
  {
  printf(" ");
  }
 
 
 
 
  for(k=1;k<4;k++)
  {
  printf("*");
  }

   printf("\n");
 }
 for(i=10;i>=1;i--)
{  for(j=1;j<=(24-(i/2));j++)
 {
  printf(" ");
 }
 for(k=1;k<=i;k++)
 {
  printf("*");
 }
 printf("\n");
 }



 printf(" pata hai dimensioning ye hai @www.Myeductionandprep.blogspot.com");
 }

Saturday, September 7, 2019

Farenhite to celcius

#include <stdio.h>

   main()
{
float F,C;
printf("enter temperature in farenhite\n");
scanf("%f",&F);
C=(F-32)*5/9;

printf("temprature in celcius is %f",C);

}

C program to Swap two numbers without using third variable

#include <stdio.h>
main()
{
int n1,n2;
printf("enter the no.1\n");
scanf("%d",&n1);
printf("enter the no.2\n");
scanf("%d",&n2);
n1=n1+n2;
n2=n1-n2;
n1=n1-n2;
printf("after swaping no.1 is %d\n",n1);
printf("after swaping no.2 is %d",n2);
}



Swap two no.using third variable

#include <stdio.h>
main()
{
int n1,n2,temp;
printf("enter the no.1\n");
scanf("%d",&n1);
printf("enter the no.2\n");
scanf("%d",&n2);
temp=n1;
n1=n2;
n2=temp;
printf("after swaping no.1 is %d\n",n1);
printf("after swaping no.2 is %d",n2);
}



Area of right angle triangle

#include <stdio.h>
main()
{    int height,base;
float area;
printf("enter the height of triangle\n" );
scanf("%d",&height);
printf("enter the base of triangle\n");
scanf("%d",&base);
area=base*height*0.5;
printf("area is %f",area);
}

Thursday, September 5, 2019

How to use the codes

You can install the compiler from given link.   https:clickhere
Then just copy the code from here and paste then run

C program to find that given number Is prime or not

#include "stdio.h"
main()
{
int n,i=2,out;
printf("enter n");
scanf("%d",&n);
for(i>1;i<n;i++)
{ if(n%i==0)
{ printf("not prime");
                  break;}

                }
                 
       
if (i==n)
    printf ("prime");}


C program to find factorial if given number

#include <stdio.h>
int main()
{
int n,fact,i=1,c;
again:
fact=1;

printf("enter n \n");
scanf("%d",&n);


while (i<=n)
{
fact=fact*i;
i++;
}
printf("%d\n",fact);
printf("enter 1 to exit else any int.\n");
    scanf("%d",&c);
    if(c!=1)
    goto again;
    else return 0;

}

Celsius to Fahrenheit (c)

#include <stdio.h>

   main()
{
float F,C;
printf("enter temperature in celcius\n");
scanf("%f",&C);
F=9/5*C+32;
printf("%f",F);

}


Implement stsStr Leetcode solution

  28.   Implement strStr() Easy Implement  strStr() . Given two strings  needle  and  haystack , return the index of the first occurrence of...