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

c Programming Exe1 1

The document contains C programming exercises from October 2018, including examples of basic input/output, conditional statements, and loops. Each exercise demonstrates different programming concepts such as checking if a number is greater than zero, using for loops, and calculating the sum of natural numbers. The exercises are structured with code snippets and comments explaining their functionality.

Uploaded by

jeresladii
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

c Programming Exe1 1

The document contains C programming exercises from October 2018, including examples of basic input/output, conditional statements, and loops. Each exercise demonstrates different programming concepts such as checking if a number is greater than zero, using for loops, and calculating the sum of natural numbers. The exercises are structured with code snippets and comments explaining their functionality.

Uploaded by

jeresladii
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

C programming exercise 2-October 2018

Exercise 1 Exercise 2
#include <stdio.h> #include <stdio.h>
int main()
{ int main()
int x; {
printf("Please enter a number:"); int x;
scanf ("%d",&x); printf("Please enter a number:");
if(x > 0){ scanf ("%d",&x);
printf("\nThe number %d is greater than 0",x); if(x > 0)
} {
return 0; printf("\nThe number %d is greater than 0",x);
} }
else
{
printf("\nThe number %d is less than or equal zero",x);
}
return 0;
}

Exercise 3 Exercise 4-for loop


#include <stdio.h> #include<stdio.h>
int main () int main()
{ {
int grades;
printf("enter your grades :");
int n;
scanf("%d",&grades); printf("How many time you want to print?"\n);
if ( grades >= 40 ) scanf(" %d ", &n);
printf("Congratulations you are passed"); for ( i = 1; i <= n; i++) //for loop which will repeat n
else times
printf("Sorry you are failed"); {
return 0; printf("simple illustration of for loop"\n);
}
}
return 0;
}
Exercise 5-C program to print the sum of Exe 6-C program to print sum of first 5 natural
first 5 natural numbers numbers using do..while loop

#include <stdio.h> #include <stdio.h>


int main () int main ()
{ {
int sum = 0, i = 1; //initialization of counter int sum = 0, i = 1; //initialization of counter variable i
variable i do
while(i <= 5) //loop to be repeated 5 times {
{ sum = sum+i;
sum = sum+i; i++; //increment of counter variable
i++; //increment of countervariable }while(i <= 5); //coondition of do while
} printf("sum of first 5 natural numbers = %d",sum);
printf("sum of first 5 natural numbers = return 0;
%d",sum); } //end of program
return 0;
} //end of program

You might also like