C Programing Basic Programs Using Printf() and Scanf() Functions
----------------------------------------------------------------------------------------------------
1. Print Simple Welcome message like “Welcome to the world of C Programming”.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Welcome to the world of C Programing");
getch();
}- OUTPUT:
Welcome to the world of C Programming
-----------------------------------------------------------------
2. Write a C Program to print the following string. (Use of Escape Sequence for “ ” DOUBLE QUOTE)
Someone Said “Nothing is Impossible”.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("\"Nothing Is Impossible\"");
getch();
}
- OUTPUT:
"Nothing Is Impossible"
-----------------------------------------------------------------
3. Write a C Program to accept Dollar and convert it into Rupees. (1 Dollar = 70 Rupees)
#include<stdio.h>
#include<conio.h>
void main()
{
int dollar,rupees;//Declare variable
clrscr();
printf("Enter Dollar");
scanf("%d",&dollar);//Get Value From User
rupees=dollar * 70;
printf("Rupees:%d",rupees);
getch();
}
- OUTPUT:
Enter Dollar: 2 //Get Value From User
Rupees : 140
-----------------------------------------------------------------
4. Write a C Program to accept any number and print its square and cube.
#include<stdio.h>
#include<conio.h>
void main()
{
int no,square,cube;
clrscr();
printf("Enter No");
scanf("%d",&no);
square=no*no;
cube=no*no*no;
printf("Square:%d",square);
printf("Cube:%d",cube);
getch();
}
- OUTPUT:
Enter No: 2
Square: 4
Square: 8
-----------------------------------------------------------------
5. Write a C Program to accept radius and calculate Area of Circle and print it.
#include<stdio.h>
#include<conio.h>
void main()
{
float radius,ans;
clrscr();
printf("Enter Radius:");
scanf("%f",&radius);
ans=3.14*radius*radius;
printf("\nArea Of Circule:%f",ans);
getch();
}
- OUTPUT:
Enter Radius: 2.5
Area Of Circule: 22.812500
-----------------------------------------------------------------
6. Write a C Program to get any two values and swap them or exchange them.
#include<stdio.h>
#include<conio.h>
void main()
{
int swap,a,b;
clrscr();
printf("Enter Value For A:");
scanf("%d",&a);
printf("\nEnter Value For B:");
scanf("%d",&b);
printf("\nBefore Swapping:");
printf(" \nA :%d" ,a);
printf("\nB :%d",b);
swap=a;
a=b;
b=swap;
printf("\n\nAfter Swapping:");
printf("\nA :%d",a);
printf("\nB :%d",b);
getch();
}
- OUTPUT:
Enter Value For A: 10
Enter Value For B : 20
Before Swapping:
A: 10
B:20
Before Swapping:
A: 20
B: 10
No comments:
Post a Comment