1. Write a program to print “ Welcome to the world of C” and “ My first C Program “ in two printf statements. Use ‘\n’ in printf statement and see what happens when we do not use ‘\n’.
Solution :-
#include<stdio.h>
#include <conio.h>
void main() {
clrscr();
printf("welcome to the world of c\n");
printf("My first c program\n");
#include <conio.h>
void main() {
clrscr();
printf("welcome to the world of c\n");
printf("My first c program\n");
getch();
}
OUTPUT:
![]() |
First C Program. |
2. Write a program using C++ to print your name and city using multiline comment.
Solution :-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"my name is Rahul Kumar"<<endl;
cout<<"i am from Khagaria";
/*Here Rahul is my name.
and khagaria is the city where i born*/
getch();
}
OUTPUT:-
3. Write a program to calculate the simple interest for input of principal, rate and time. (Hint : (P*R*T)/100)
Solution :-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
intp,r,t,si;
cout<<"Enter the principal value p:";
cin>>p;
cout<<"Enter the rate of intrest r:";
cin>>r;
cout<<"Enter the time t:";
cin>>t;
si=(p*r*t)/100;
cout<<"The simple intrest of given value"<<si;
getch();
}
OUTPUT:-
![]() |
Simple Interest program. |
4. Write a program to swap the values of two variable using a third variable.
Solution :-
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr ();
inta,b,c;
cout<<"Enter the values of a & b";
cin>>a>>b;
c=a;
a=b;
b=c;
cout<<"After swaping the value of a";
cout<<a<<endl;
cout<<"After swaping the value of b";
cout<<b;
getch();
}
OUTPUT:-
![]() |
Swapping using third variable. |
5. Write a program to swap the values of two variable without using a third variable.
Solution :-
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr ();
inta,b;
cout<<"Enter the values of a & b";
cin>>a>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"After swaping the value of a";
cout<<a<<endl;
cout<<"After swaping the value of b";
cout<<b;
getch();
}
OUTPUT:-
Note:- For more programs of C++ please subscribe and follow this Blog.
Also please share this with your friends.
No comments: