simple practice programs and solutions

 In This article we have discuss about simple practice programs and solutions , it can also be say that our first program in C ,so let's discuss.

programs :-



(1)    Write a program to print your name .

#include <stdio.h>
int main()
{
printf("Hello ,my name is Adarsh\n");
return 0;
}

Compile and run:-


(2) Write a program to sum two given numbers .


#include<stdio.h>
int main( )
{
  int a,b,s;
  printf("Enter the first number =  ");
  scanf("%d,&a);
  printf("Enter the second number =  ");
  scanf("%d",&b);
  s=a+b;
    printf(" The sum is = %d ",s);
return 0;
}

(3)  Write a program to calculate area of a circle .

include<stdio.h>
int main()
{
int r;
float area;
printf("Enter radius of the circle = ");
scanf("%d",&r);
area=3.14*r*r;
printf("Area of the circle is = %.2f ",area);
return 0;
}

(4) Write a program to print your name at the center of the screen.

#include<stdio.h>
#include<conio.h>
void main()
{
    gotoxy(40,13);
    printf ( " Code with AD ");
}


(5)  Write a program to multiply to floating points numbers .

#include <stdio.h>
int main()
 {
    float a, b, product;
    printf("Enter two numbers: ");
    scanf("%f  %f", &a, &b);  
    product = a * b;
// %.2f is used to print only 2 char after decimal
    printf("Product = %.2f", product);
    
    return 0;
}

Compile and run:-


Note :- // is used to one line comment in program or  /*  .......    ...    */  is used to multi line program . 


In our next Article we will discuss about Statements in C , So keep reading .


Code with AD

Hii connection! This is Adarsh Kumar_ From Patna , Bihar(India)_ I am pursing graduation from AN college, Patna.

1 Comments

Post a Comment
Previous Post Next Post