0% found this document useful (0 votes)
21 views6 pages

Week 1 C Lab

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

Week 1 C Lab

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

WEEK-1

INTODUCTION TO PROGRAMMING
PROGRAM 1: Program to swap two numbers without using third variable
using c.

CODE:

#include <stdio.h>

int main() {

int a =10;

int b=20;

printf("A before swap :%d\n",a);

printf("B before swap :%d\n",b);

a = a+b;

b= a-b;

a=a-b;

printf("A After swap :%d\n",a);

printf("B After swap :%d\n",b);

return 0;

OUTPUT:

PROGRAM 2: Program to find second largest number in an array using c.

CODE:

#include <stdio.h>

int main() {
int array[] = {2,5,7,10,89,16};

int max = array[0];

int s_max = array[0];

printf("Elements in array: \n");

for(int i=0;i<sizeof(array)/4;i++){

if(array[i]>max){

max = array[i];

else if(array[i]>s_max && s_max<max){

s_max = array[i];

printf("Element-%d: ",(i+1));

printf("%d\n",array[i]);

printf("Largest number: %d\n",max);

printf("Second largest number: %d",s_max);

return 0;

OUTPUT:

PROGRAM 3: Program to reverse three digit number without using loop


using c.

CODE:
#include <stdio.h>

int main() {

int a = 1234,b=a;

int rev = 0;

start:

rev = rev*10 + a % 10;

a=a/10;

if(a!=0){

goto start;

printf("Given number :%d\n",b);

printf("Reversed number :%d\n",rev);

return 0;

OUTPUT:

PROGRAM 4: Program to take as input 5 integers. The program then


outputs all inputs that are largest then the average of the 5 input integers
using c.

CODE:

#include <stdio.h>

int main() {

int a,max=0,array[5];

double avg = 0,sum=0;


for(int i=0;i<5;i++){

printf("Number- %d: ",(i+1));

scanf("%d",&a);

array[i]=a;

sum+=a;

if(a>max){

max=a;

avg = sum/5;

for(int i=0;i<5;i++){

if(array[i]>avg){

printf("Number largest than average: %d\n",array[i]);

printf("Largest in given numbers :%d\n",max);

printf("Sum of given numbers :%lf\n",sum);

printf("Average of given numbers :%lf\n",avg);

return 0;

OUTPUT:
PROGRAM 5: Program to read the input values , evaluate each of the
following equation using c and print the output .

(i) V= u+at. (ii)S=ut+1/2a (iii) 2a+ √b+9c

CODE:

#include <stdio.h>

#include <math.h>

int main() {

int b,u,a,t,c;

printf("Enter the value of (b): ");

scanf("%d",&b);

printf("Enter the value of (u): ");

scanf("%d",&u);

printf("Enter the value of (a): ");

scanf("%d",&a);

printf("Enter the value of (t): ");

scanf("%d",&t);

printf("Enter the value of (c): ");

scanf("%d",&c);

int v=u+a*t;

int s = u*t+(a/2);
double T=2*a+sqrt(b)+9*c;

printf("V=u+at value: %d\n",v);

printf("S=ut+1/2a value: %d\n",s);

printf("T=2a+b^(1/2)=9c value: %lf",T);

return 0;

OUTPUT:

You might also like