0% found this document useful (0 votes)
52 views

C Assignment

The document contains the solutions to 9 questions on C programming assignments submitted by Prerna Rathore with roll number 0261016202. The solutions demonstrate various basic C programming concepts like printing output, taking input, performing arithmetic operations on numbers, using loops, functions, arrays and recursion. Sample outputs are provided for each question.

Uploaded by

Prerna Rathore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

C Assignment

The document contains the solutions to 9 questions on C programming assignments submitted by Prerna Rathore with roll number 0261016202. The solutions demonstrate various basic C programming concepts like printing output, taking input, performing arithmetic operations on numbers, using loops, functions, arrays and recursion. Sample outputs are provided for each question.

Uploaded by

Prerna Rathore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Assignment 1

Name-PRERNA RATHORE
Roll No.- 0261016202
Tool used- Visual Studio code

Q1-:Hello world
Sol-
#include<stdio.h>
#include<conio.h>

void main()
{
printf("Hello World");

Output-:

Q2-:sum of 2 number.
Sol-
#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,Sum;
printf("Enter First No. -:");
scanf("%d",&a);
printf("Enter Second No. -:");
scanf("%d",&b);
Sum= a+b;
printf("Sum Of two no. is %d",Sum);

OutPut-:

Q3-:performing basic operations on 2 nos. ( Addition ,


subtraction, multiplication, division).
Sol-: Addition-:
#include <stdio.h>
#include <conio.h>

void main()
{
float a, b;
float Addition;
printf("Enter number -:");
scanf("%f",&a);
printf("Enter number -:");
scanf("%f",&b);
Addition = a+b;
printf("Addition of no. is : %f", Addition);
getch();
}
OutPut-

Subtraction-:
#include <stdio.h>
#include <conio.h>

void main()
{
float a, b;
float Subtraction;
printf("Enter number -:");
scanf("%f",&a);
printf("Enter number -:");
scanf("%f",&b);
Subtraction= a-b;
printf("Subtraction of two no. is : %f",Subtraction);
getch();
}

Output-:
Multiplication-:
#include <stdio.h>
#include <conio.h>

void main()
{
float a, b;
float Multiplication;
printf("Enter number -:");
scanf("%f",&a);
printf("Enter number -:");
scanf("%f",&b);
Multiplication= a*b;
printf("Multiplication of two no. is : %f",Multiplication);
getch();
}

OutPut-:

Division-:
#include <stdio.h>
#include <conio.h>

void main()
{
float a, b;
float Divide;
printf("Enter number -:");
scanf("%f",&a);
printf("Enter number -:");
scanf("%f",&b);
Divide = a/b;
printf("Result Is : %f", Divide);
getch();
}

OutPut-:
Q4-:printing 1-10 using loop
Sol-:
#include <stdio.h>
#include <conio.h>

void main()
{
int a;
printf("Numbers by loop are -:");
for (a=1;a<=10;a++)
{
printf("%d ",a);
}
printf("\n");
}

OutPut-:

Q5-:printing table and printing 1-10 in reverse order.


Sol-:
#include <stdio.h>
#include <conio.h>

void main()
{
int i,a;
printf("\nEnter the table number:");
scanf("%d",&a);
for(i=10;i>=1;i--)
{
printf("\n%d*%d=%d",i,a,i*a);
}
printf("\n");
}

OutPut-:

Q6-:making calculator using function


Sol-:
Calculator-:
#include <stdio.h>
#include <conio.h>

void main()
{
char opertion;
float x,y,add,subtraction,division,multiplication;

printf("Enter First Number\n");


scanf("%f",&x);
printf("Enter Second Number\n");
scanf("%f",&y);
scanf("%c", &opertion);

printf("Choose Opertion\n ");


printf("For addition press a\n");
printf("For subtraction press s\n");
printf("For division press d\n");
printf("For multiplication press m\n");
scanf("%c", &opertion);

if (opertion=='a')
{
add = x+y;
printf("The addition of two number is %f",add);
}
if (opertion=='s')
{
subtraction = x-y;
printf("The subtraction of two number is %f",subtraction);
}
if (opertion=='m')
{
multiplication = x*y;
printf("The multiplication of two number is %f", multiplication);
}
if (opertion=='d')
{
division = x/y;
printf("The division of two number is %f", division);
}

getch ();

OutPut-:
Q7-: Print table of given number
Sol-:
#include<stdio.h>
int main()
{
int i,a;
printf("enter the no: ");
scanf("%d", &a);

for(i=1;i<=10;++i)
{
printf("%d * %d = %d\n",a,i,a*i);
}
return 0;
}
OutPut-:

Q8-: To make in array and find their sum,average and percentage


Array sum and avg-:
#include <stdio.h>

int main()
{
int Arr[100], n, i, sum = 0;

printf("Enter the number of elements you want to insert : ");


scanf("%d", &n);

for (i = 0; i< n; i++)


{
printf("Enter element %d : ", i + 1);
scanf("%d", &Arr[i]);
sum += Arr[i];
}

printf("\nThe sum of the array is : %d", sum);


printf("\nThe average of the array is : %0.2f", (float)sum / n);
return 0;
}

OutPut-:

Q9- To find factorial using recursion


Factorial using recursion-:
#include<stdio.h>

int fact(int);
int main()
{
int x,n;
printf(" Enter the Number to Find Factorial :");
scanf("%d",&n);

x=fact(n);
printf(" Factorial of %d is %d",n,x);

return 0;
}
int fact(int n)
{
if(n==0)
return(1);
return(n*fact(n-1));
}
OutPut-:

You might also like