Thursday 27 May 2021

C problems

 

// write a program to find any number raise power
//author: Upendra Date:10/27/2020
#include <math.h>
void main()
{
    int abn;
    printf("Enter the two number to get power:\n");
    scanf("%d%d", &b, &n);
    a = pow(bn);
    printf("Answer is %d"a);
}


/*write a program to print all
even number from 1 to 100*/
#include<stdio.h>
void main()
{
int n=1;
for(n=1;n-->=1&&n--<=100)
printf("%d\n",n);
}


/* write a program to print
alphabet from a to z*/
#include<stdio.h>
void main()
{
char ch='A';
while(ch<='Z')
{
printf("%c\n",ch);
ch++;}
}


// rectangle
#include <stdio.h>
int main()
{

    int a = 32;
    int b = 32;
    printf("area of rectangle is a*b is %d"a * b);
    return 0;
}


// rectangle
# include<stdio.h>
int main(){

int a;
int b;
int c;
printf("length of rec is a:");
scanf("%d",&a);
printf("breadth of rec is b:");
scanf("%d",&b);
c=a*b;
printf("area of rectangle is a*b is %d",c);
return 0;



}


// area of circle
# include<stdio.h>
int main(){

float r,a;
printf("Radius of a circle is r:");
scanf("%f",&r);
printf("area of circle is %f",r*r);
return 0;


}


// volume of cylinders
# include<stdio.h>
main(){
float v,r,h; // v- volume , pi- 3.14, r-radius,h-height
float pi=3.14;
printf("Enter the radius of cyclinders:");
scanf("%f",&r);
printf("Enter the height of cyclinders:");
scanf("%f",&h);
v=pi*(r*r)*h;
printf("Volume of a cyclinder is %f",v);



}

# include<stdio.h>
main(){
float c,f; // c - celsius, f- fahreint
printf("Enter the temperature in celsius:");
scanf("%f",&c);
f=(c*9/5)+32;
printf("temperature in faherient is %f",f);

}


// find the final amount in simple interest of shaam
# include<stdio.h>
main(){
float Si,p,r,Total_Amount; // simple inters, principle , rate of interest, time of year
int t;
printf("Enter the principle amount:");
scanf("%f",&p);
printf("Enter the rate of  interest:");
scanf("%f",&r);
printf("Enter the time in year:");
scanf("%d",&t);
Si=(p*r*t)/100;
printf("Simple interest of shaamu is %f \n\n",Si);
Total_Amount=p+Si;
printf("Total Amount after %d year is %f",t,Total_Amount);



}


#include <stdio.h>

int main()
{
    int a = 16, c, u, b;
    a = c = u = b;
    printf("The value of a is %d \n", c);
    printf("The value of a is %d", u);
}


#include <stdio.h>

int main()
{
   int marks1,marks2,marks3,Total_marks;
   printf("Enter the marks of each subject:\n ");
   scanf("%d%d%d \n",&marks1,&marks2,&marks3);
   Total_marks=(marks1+marks2+marks3)/3*3;
   printf("Total_marks of Student is %d \n",Total_marks);
   if ((marks1>=33&&marks2>=33&&marks3>=33)&&(Total_marks>=40))
   {
       printf("You are passed CongraT!");
   }
   else
   {
    printf("You are Fail");
   }




    return 0;
}



// create a program to add and sub and multi and divide two number
# include<stdio.h>

int main(){

int a = 25;
int b= 30;
int c ;
c = a+b;
printf("Sum of a and b is %d",c);
return 0;

}



// write a program to find area of retangle using

# include<stdio.h>

int main(){

int l,b,a; // area of rectangle
printf("length of rectangle is :");
scanf("%d",&l);
printf("breadth of rectangle is :");
scanf("%d",&b);
a=l*b;
printf("area of rec is %d",a);
return 0;



}



#include<stdio.h>
int main()
{
int i,j,rows; // N is no. of rows
printf("Enter the no.of rows:\n");
scanf("%d",&rows);
for(i=1;i<=rows;i++)
{
for(j=1;j<=rows-i;j++)
{
printf(" ");}

for(j=1;j<=(2*i-1);j++)
{
if(j==1||i==rows||j==(2*i-1))

printf("*");
else
{
    printf(" ");
}
}

printf("\n");

}











}


/**
 * C program to print equilateral triangle or pyramid star pattern
 */

#include <stdio.h>

int main()
{
    int i, j, rows;

    /* Input number of rows to print */
    printf("Enter number of rows : ");
    scanf("%d", &rows);

    /* Iterate through rows */
    for(i=1; i<=rows; i++)
    {
        /* Print leading spaces */
        for(j=i; j<rows; j++)
        {
            printf(" ");
        }

        /* Print star */
        for(j=1; j<=(2*i-1); j++)
        {
            printf("*");
        }

        /* Move to next line */
        printf("\n");
    }

    return 0;
}



// write  a program to print pyramid pattern in c
#include <stdio.h>
int main()
{
    int ijN// N is no of input row
    printf("Enter the input row:\n");
    scanf("%d", &N);
    for (i = 1i <= Ni++)
    {
        for (j = 1j < Nj++)
        {
            printf(" ");
        }

        for (j = 1j <= (2 * i - 1); j++)
        {
            printf("*");
        }

        printf("\n");
    }
}


// write a program to draw pyramid using star pattern
#include <stdio.h>
int main()
{
    int ijNM// N is a row input and M is a col
    printf("Enter the input rows and col");
    scanf("%d%d", &N, &M);
    for (i = 1i <= Ni++)
    {
        for (j = 1j <= Mj++)
        {
            printf("*");
        }

        printf("\n");
    }
}



// write a program to find area of retangle using

# include<stdio.h>

int main(){

int l,b,a; // area of rectangle
printf("length of rectangle is :");
scanf("%d",&l);
printf("breadth of rectangle is :");
scanf("%d",&b);
a=l*b;
printf("area of rec is %d",a);
return 0;



}



// write a program to build a structure like of black square emoji
#include<stdio.h>
int main()
{
int i,j,N//ith row ,jth column,N is a no. of rows
printf("Enter the no. of rows:\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
for(j=1;j<=N;j++)
{
if(i==1||i==N||j==1||i==N-5||i==5||j==5)
printf("*");
else
{
printf(" ");
}

}

printf("\n");

}
}

No comments:

Python if / else

 Python if / else a1 = int ( input (" Enter the number: \n ")) a2 = int ( input (" Enter the number: \n ")) a3 = int ( i...