C Que & Sol
C Que & Sol
_____________________
INPUT/OUTPUT QUESTIONS
_____________________
1) Write a C program that prints the perimeter of a rectangle to take its height and width as input
int l,b;
printf("enter the value of length:");
scanf("%i",&l);
printf("enter the value of breadth:");
scanf("%i",&b);
printf("the perimeter of rectangle is %i",2*(l+b));
2)Write a C program that takes hours and minutes as input, and calculates the total number
of minutes.
Expected Output :
Input hours: 5
Input minutes: 37
Total: 337 minutes.
int hrs,min;
printf("enter the value of hrs:");
scanf("%i",&hrs);
5hrs 37mins
printf("enter the value of min:");
hrs=>hrs*60=minutes hours->min->mul by 60
scanf("%i",&min);
printf("total minutes are %i ",(hrs*60)+min);
3)Write a program in C that takes minutes as input, and display the total number of hours and
minutes.
Expected Output :
Input minutes: 546
9 Hours, 6 Minutes
int minutes;
printf("enter the value of minutes:");
546->hrs 546/60=9hrs
scanf("%i",&minutes);
min->hours->div by 60
int hours=minutes/60;
int remaining min=minutes%60;
printf("total hours are %i ",hours);
printf("\ntotal min are %i ",min);
float cent; .
cent-> frah
printf("enter the value of cent:");
scanf("%f",¢);
printf("the temp in frah is %.2f",(1.8*cent)+32);
5) Write a C program that converts kilometers per hour to miles per hour.
float km;
printf("enter the value of (km/h):");
scanf("%f",&km);
printf("the temp in frah is %.2f",(km/1.609344));
__________________________
CONDITIONAL QUESTIONS
__________________________
6)Write a C program to accept two integers and check whether they are equal or not.
int a;
printf("enter the value of a");
scanf("%i",&a);
if(a%2==0)
{
printf("given number is even");
}
else
{
printf("number is odd");
}
int n;
printf("enter the value of n:");
scanf("%i",&n);
if(n>0)
{
printf("the number is a positive number");
}
else
{
printf("the number is a negative number");
}
// ( year%100==0)
// 2 type year- century year - 1900, 2000,1700 year%400==0-leap year else not leap
// non century year 1996 2004 2008 1224 %4==0
int n;
scanf("%i",&n);
if((n%400==0 || n%4==0 )&& n%100 != 0 ){
printf("year is laep year");
}
else{
printf("year is not a leap year");
}
10) Write a C program to read the age of a candidate and determine whether it is eligible
for casting his/her own vote.
int age;
printf("enter the age:");
scanf("%i",&age);
if(age>=18)
{
printf("he has the right to vote");
}
else
{
printf("he dont the right to vote");
}
11) Write a C program to read the value of an integer m and display the value of n is 1 when
m is
larger than 0, 0 when m is 0 and -1 when m is less than 0.
int m;
printf("enter the value of m:");
scanf("%i",&m);
if(m>0)
{
printf("the value of n is 1");
}
else if(m==0)
{
printf("the value of n is 0");
}
else
{
printf("the value of n is -1");
}
12)Write a C program to accept the height of a person in centimeter and categorize the person
according to their height if below 150 he is dwarf if above 150 and below 200 average and
above 200 tall.
int h;
printf("enter the value of height:");
scanf("%i",&h);
if(h<150)
{
printf("dwarf");
}
else if(h>150 && h<200)
{
printf("average");
}
else
{
printf("he is tall");
}
13)Write a C program to find the largest of three numbers.
int a=5,b=2,c=0;
if(a>b && a>c)
{
printf("a is greatest");
}
else if(b>a && b>c){
printf("b is greatest");
}
else
{
printf("c is greatest");
int m1,m2,m3,m4;
scanf("%i %i %i %i",&m1,&m2,&m3,&m4);
int average = (m1+m2+m3+m4)/4;
if(average<=35)
{
printf("grade is F");
}
else if(average<=45)
{
printf("grade is D");
}
else if(average<=55)
{
printf("grade is C");
}
else if(average<=75)
{
printf("grade is B");
}
else if(average>=75)
{
printf("grade is A");
}
16)Write a C program to calculate profit and loss on a transaction accept cost price and
selling price.
int cp=200;
int sp=400;
if(sp>cp)
{
profit=sp-cp;
printf("%i ",profit);
}
else if(cp>sp)
{
loss=cp-sp;
printf("%i ",loss);
}
else
{
printf("no profit no loss");
}
18)Accept two numbers from user and swap their values without using third variable
int a=10;
int b=20;
a=a+b;
b=a-b;
a=a-b;
printf("%i",a);
printf("%i",b);
______________________
LOOPS QUESTION
______________________
#include <stdio.h>
int main()
{
// hello world n times
int n;
printf("Enter n : ");
scanf("%i",&n);
for(int i=1; i<=n; i++){
printf(" Hello World\n");
}
return 0;
}
#include <stdio.h>
int main()
{
// natural number upto n
int n;
printf("Enter n : ");
scanf("%i",&n);
for(int i=1; i<=n; i++){
printf("%i\n",i);
}
return 0;
}
#include <stdio.h>
int main()
{
// natural number upto 1
int n;
printf("Enter n : ");
scanf("%i",&n);
for(int i=n; i>=1; i--){
printf("%i\n",i);
}
return 0;
}
int n;
printf("enter the value of n:");
scanf("%i",&n);
for(int i=1; i<11; i++){
printf("%i*%i = %i\n",n,i,n*i);
23 - Sum up to n terms.
int n;
printf("enter the value of n:");
scanf("%i",&n);
int sum=0;
for(int i=1; i<n; i++){
sum=sum+i;
}
printf("%i",sum);
24 - Factorial of a number
int n;
scanf("%i",&n);
int fact=1;
for(int i=n; i>=0; i--){
fact=fact*i;
}
printf("the value of fact is %i",fact);
#include <stdio.h>
int main(){
// 3/5
int n;
printf("Enter range:");
scanf("%i",&n);
for(int i=1; i<=n; i++){
if(i%3==0||i%5==0){
printf(" %i ",i);
}
}
return 0;
}
#include<stdio.h>
int main(){
// factors
int n,fact;
printf("Enter n:");
scanf("%i",&n);
for(int i=1; i<=n; i++){
fact=n%i;
if(fact==0){
printf("%i\n",i);
}
}
return 0;
}
int n;
scanf("%i",&n);
int evensum=0,oddsum=0;
for(int i=1; i<n; i++)
{
if(i%2==0)
{
evensum=evensum+i;
}
else
{
oddsum=oddsum+i;
}
}
printf("%i %i ",evensum,oddsum);
int n;
scanf("%i",&n);
int copy=n;
int sum=0;
while(n>0) {
int rem=n%1
0;
sum=sum+rem; n=n/10; } printf("sum is %i",sum);
#include<stdio.h>
int main(){
// prime
int n,count=0;
printf("Enter any number : ");
scanf("%i",&n);
for(int i=1; i<=n; i++){
if(n%i==0){
count++;
}
}
if(count==2){
printf("prime number ");
}
else{
printf("Not a prime number ");
}
10
return 0;
}
#include<stdio.h>
int main(){
// prime
int n,rem;
printf("Enter any number : ");
scanf("%i",&n);
while(n>0){
rem=n%10;
printf("%i",rem);
n=n/10;
}
return 0;
}pp
32 - Accept a number and check if it is a pallindromic number (If number and its reverse are
equal)
Ex - 12321 - Rerverse - 12321
int n;
scanf("%i",&n);
int copy=n;
int sum=0;
int rev=0;
while(n>0)
{
int rem=n%10; 123 321 121 121
rev=rev*10+rem;
n=n/10;
}
if(copy==rev)
{
printf("its an pal number");
}
33 - Accept a number and check if it is a armstrong number (Sum of cube of all digits will be
equal to origional number)
Ex - 407 = 64 + 0 + 343 = 407
153 = 1 + 125 + 27 = 153
int n;
scanf("%i",&n);
int copy=n;
int sum=0;
while(n>0)
{153
int rem=n%10;
sum=sum+rem*rem*rem;
n=n/10;
}
if(copy==sum)
{
printf("its an armstrong number");
}
34 - Accept a number and check if it a perfect number or not.
A number whose sum of factors(excluding number itself) = Number
Ex - 6 = 1, 2, 3 = 6
int n;
scanf("%i",&n);
int sum=0;
for(int i=1; i<=n/2; i++) // 6=1 2 3
12=6 10=5
{
if(n%i==0)
{
printf("%i ",i);
sum=sum+i;
}
}
if(sum==n)
{
printf("its a perfect number");
}
35 - Accept a number and check if it is a strong number or not (Sum of factorial of each digit)
Ex- 145 = 1! + 4! + 5! = 145
int n;
scanf("%i",&n);
int sum=0;
int copy=n;
while(n>0)
{
int rem=n%10; 1 4 5 // 1! + 4!+5!
int fact=1;
for(int i=1; i<=rem; i++) // 4=4*3*2*1
{
fact=fact*i;
}
sum=sum+fact;
n=n/10;
}
if(sum==copy)
{
printf("its a strong number");
}
#include <stdio.h>
int main()
{
//harshad number
int n,rem;
printf("Enter any number : ");
scanf("%i",&n);
while(n>0)
{
rem=n%10;
printf("%i \n",rem);
n=n/10;
}
return 0;
}
#include <stdio.h>
int main ()
{
int num, prev = 0, curr = 1, next;
printf("Enter max length : ");
scanf("%i",&num);
printf("%i %i ",prev,curr);
for (int i = 1; i <= num-2; i++)
{
next=prev+curr;
prev=curr;
curr=next;
printf ("%i ", next);
}
return 0;
}
int n1,n2;
scanf("%i %i",&n1,&n2);
int lcm,g;
if(n1>n2)
{
g=n1;
}
else
{
g=n2;
}
// lcm = least common multiple
lcm=voh number jo aur b dono se divide ho
// 2= 2,4,6,8,10,12 6=6,12,18,24
a*b=tk le jyenge ; 6 se chota nhi ho skta answer
// RANGE= MINIMUN=largest of two;
MAXIMUM=multiply kr do dono ko;
for(int i=g; i<=n1*n2; i++)
{
if(6%2==0 && 6%6==0)
{
lcm=i;
break;
}
}
printf("the lcm is %i",lcm);
40 - Write a program in C to find the sum of the series 1 +11 + 111 + 1111 + .. n terms.
int n;
scanf("%i",&n);
int sum=0;
int prev=0;
for(int i=0; i<n; i++) // 10*1=10 111
10*2=100
{
prev=pow(10,2)+prev; // 10*0=1 1+10+100
//
1+11+111+1111=1234
if(i==n-1)
{
printf("%i = ",prev);
}
else
{
printf("%i +",prev);
}
sum=sum+prev;
}
______________________
ARRAY PROBLEMS
______________________
#include <stdio.h>
int main(){
int a[5];
printf("Enter array elements\n");
for(int i=0; i<5; i++){
scanf("%i",&a[i]);
}
printf("Array elememts are\n");
for(int i=0; i<5; i++){
printf("%i ",a[i]);
}
return 0;
}
#include <stdio.h>
int main()
{
int a[5];
printf("Enter array elements\n");
for(int i=0; i<5; i++){
scanf("%i",&a[i]);
}
printf("Elements in reverse order\n");
for(int i=4; i>=0; i--){
printf("%i ",a[i]);
}
return 0;
}
#include<stdio.h>
int main(int argc, char const *argv[])
{
int size;
printf("enter the size of an array\n");
scanf("%i", &size);
int arr[size];
for (int i = 0; i < size; i++)
{
scanf("%i", &arr[i]);
}
printf("positives:");
for (int i = 0; i < size; i++)
{
if (arr[i]>=0)
{
printf("%i ", arr[i]);
}
}
printf("\nnegatives:");
for (int i = 0; i < size; i++)
{
if (arr[i]<0)
{
printf("%i ", arr[i]);
}
}
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
int size;
printf("enter the size of an array\n");
scanf("%i", &size);
int arr[size];
for (int i = 0; i < size; i++)
{
scanf("%i", &arr[i]);
}
printf("ascending:");
for (int i = 0; i < size; i++)
{
printf("%i ", arr[i]);
}
printf("\ndescending:");
for (int i = size - 1; i >= 0; i--)
{
printf("%i ", arr[i]);
}
return 0;
}
45 - Accept size n from user and create a n size array then take n inputs into the and finally
Print the sum of all elements in the array in the following manner
10 + 20 + 30 = 60
int n;
scanf("%i",&n);
int arr[n];
int sum=0;
for(int i=0; i<n; i++)
{
scanf("%i",&arr[i]);
}
for(int i=0; i<n; i++)
{
printf("%i",arr[i]);
sum=sum+arr[i];
}
printf("the sum is %i",sum);
#include <stdio.h>
int main()
{
int size, sum=0;
scanf("%i",&size);
int arr[size];
for(int i=0; i<size; i++){
scanf("%i",&arr[i]);
}
for(int i=0;i<size;i++){
sum=sum+arr[i];
}
printf("mean is %i",sum/size);
return 0;
}
#include <stdio.h>
int main()
{
int size, gi;
int arr[size];
printf("Enter size\n");
scanf("%i",&size);
for(int i=0; i<size; i++){
scanf("%i",&arr[i]);
}
gi = 0;
for(int i=1; i<size; i++){
if(arr[gi]<arr[i]){
gi=i;
}
}
printf("greatest is %i and its index is %i",arr[gi],gi);
return 0;
}
int main()
{
int n;
scanf("%i",&n);
int arr[n];
for(int i=0; i<n; i++)
{
scanf("%i",&arr[i]);
}
int gi=0;
for(int i=0; i<n; i++)
{
if(arr[i]>arr[gi])
{
gi=i;
}
}
printf("the greatest index is found at %i and the number is %i ",gi,arr[gi]);
int sgi=1;
for(int j=0; j<n; j++)
{
if(arr[j]!=arr[gi])
{
sgi=j;
printf("%i",sgi);
}
}
printf("the second greatest index is found at %i and the number is %i",sgi,arr[sgi]);
int arr[]={2,1,96,69,77,145,20};
int count=sizeof(arr)/sizeof(int);
int si=0;
for(int i=1; i<count; i++)
{
if(arr[si]>arr[i])
{
si=i;
}
}
printf("the smallest index is found at %i and the number is %i",si,arr[si]);
50 - Pallindromic array - Write a program to check if elements of an array are same or not it read
from front or back
Example : arr= [2,3,15,15,3,2]
int n;
scanf("%i",&n);
int arr[n];
int check=0;
int last=n-1;
for(int i=0; i<n; i++)
{
scanf("%i",&arr[i]);
}
printf("%i",last);
for(int i=0; i<=n/2; i++)
{
if(arr[i] != arr[last])
{
check=1;
}
last--;
}
if(check==1)
{
printf("its not a pal");
}
//left rotat by 1
int main()
{
int n;
scanf("%i",&n);
int arr[n];
for(int i=0; i<n; i++)
{
scanf("%i",&arr[i]);
}
int copy=arr[0];
for(int i=0; i<n; i++)
{
arr[i]=arr[i+1];
}
arr[n-1]=copy;
for(int i=0; i<n; i++)
{
printf("%i ",arr[i]);
}
return 0;
}
// right r by one
int n;
scanf("%i",&n);
int arr[n];
for(int i=0; i<n; i++)
{
scanf("%i",&arr[i]);
}
int copy=arr[n-1];
for(int i=n-1; i>=0; i--)
{
arr[i]=arr[i-1];
}
arr[0]=copy;
for(int i=0; i<n; i++)
{
printf("%i ",arr[i]);
}
//linear search
int n;
scanf("%i",&n);
int arr[n];
int check=0;
int last=n-1;
for(int i=0; i<n; i++)
{
scanf("%i",&arr[i]);
}
int s=4;
for(int i=0; i<n; i++)
{
if(s==arr[i])
{
printf("element is found at %i index",i);
check=1;
}
}
if(check==0)
{
printf("the number is not found ");
}
//binary search
int n;
scanf("%i",&n);
int arr[n];
int check=0;
for(int i=0; i<n; i++)
{
scanf("%i",&arr[i]);
}
int start=0;
int end=n-1;
int middle=(start+end)/2;
int s=8;
printf("%i",middle);
while(start<=end)
{
if(s==arr[middle])
{
printf("the number is found at %i",middle);
check=1;
break;
}
else if(s>arr[middle])
{
start=middle+1;
middle=(start+end)/2;
}
else if(s<arr[middle])
{
end=middle-1;
middle=(start+end)/2;
}
}
57 - Move all the negative elements on left side and positive elements on right side
//sort
int arr[]={25,-1,-2,3,1};
int size=sizeof(arr)/sizeof(int);
for(int j=1; j<size; j++)
{
for(int i=0; i<size-1; i++)
{
if(arr[i]>arr[i+1])
{
int temp=arr[i+1];
arr[i+1]=arr[i];
arr[i]=temp;
}
}
}
for(int i=0; i<size; i++)
{
printf("%i ",arr[i]);
}
58 - Bubble Sort.
int arr[]={25,-1,-2,3,1};
int size=sizeof(arr)/sizeof(int);
for(int j=1; j<size; j++)
{
for(int i=size-1; i>0; i--)
{
if(arr[i]<arr[i-1])
{
int temp=arr[i-1];
arr[i-1]=arr[i];
arr[i]=temp;
}
}
}
for(int i=0; i<size; i++)
{
printf("%i ",arr[i]);
}
//median
#include <stdio.h>
int
main ()
{
int size;
printf ("Enter size of an array\n");
scanf ("%i", &size);
int arr[size];
for (int i = 0; i < size; i++)
{
scanf ("%i", &arr[i]);
}
for (int j = 0; j < size; j++)
{
for (int i = 0; i < size - 1; i++)
{
if (arr[i] > arr[i + 1])
{
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
}
}
for (int i = 0; i < size; i++)
{
printf ("%i ", arr[i]);
}
int mid;
mid = (size - 1) / 2;
if (size % 2 == 0)
{
float newmid = (float) (arr[mid] + arr[mid + 1]) / 2;
printf ("\nmedian is %.2f", newmid);
}
else
{
printf ("\nmedian is %i", arr[mid]);
}
return 0;
}
60 - given an array input a number and print how many times it has appeared
int a=1;
int arr[5]={1,1,1,2,3};
int n=5;
int check=0;
int count=0;
for(int i=0; i<n;i++)
{
if(arr[i]==a)
{
count++;
check=1;
}
}
if(check==0)
{
printf("element not found");
}
else
{
printf("element is found and apperaed %i times",count);
}
#include <stdio.h>
#include<stdlib.h>
int main() {
// Write C code here
int arr[]={1,2,2,2,2,5,99,100,1,1,1};
int size=sizeof(arr)/sizeof(int);
int *occ=calloc(100,sizeof(int));
for(int i=0;i<size;i++)
{
occ[arr[i]]++;
}
for(int i=1;i<=100;i++)
{
if(occ[i]>0)
{
printf("%i comes %i times\n",i,occ[i]);
}
}
return 0;
}
_______________________
STRING QUESTIONS
_______________________
#include <stdio.h>
int main() {
char str[100];
fgets(str,100,stdin);
printf("%s ",str);
return 0;
}
63 - Write a program in C to find the length of a string
#include <stdio.h>
int main() {
char str[100];
fgets(str,100,stdin);
int i=0;
while(str[i]!='\0')
{
i++;
}
printf("the length of string is %i",i);
// we have to count \0 as well
return 0;
}
#include <stdio.h>
int main() {
char str[100];
fgets(str,100,stdin);
int i=0;
while(str[i]!='\0')
{
printf("%c ",str[i]);
i++;
}
return 0;
}
#include <stdio.h>
int main() {
// Write C code here
char str[100];
fgets(str,100,stdin);
int count=0;
int i=0;
while(str[i]!='\0')
{
count++;
i++;
// sirf i bhi le skte ho gar count varaible nhi lena hai toh
}
for(int j=count-1; j>=0;j--)
{
printf("%c",str[j]);
}
return 0;
}
#include <stdio.h>
int main() {
char str[100];
fgets(str,100,stdin);
int i=0;
while(str[i]!='\0')
{
i++;
}
printf("the length of string is %i",i-1);
// \0 ko include nhi krna esliye humne i-1 kiya hai
return 0;
}
#include <stdio.h>
// agar while loop se length nikal to yaad rkhna humesha i-1 krna pdhta hai
int main() {
// Write C code here
char str1[100];
fgets(str1,100,stdin);
char str2[100];
fgets(str2,100,stdin);
int check=0;
//size ko calculate krne k liye while loop ka use kr skte hai mai ek built in function ka use kr rhi
hu
int len1=strlen(str1);
int len2=strlen(str1);
if(len1 != len2)
{
printf("the are not equal");
}
else
{
int i=0;
while(str1[i] !='\0')
// yha pe str1 str2 dono likh skte hai kyunki dono ki length same hai
{
if(str1[i] != str2[i])
{
printf("they are not equal");
check=1;
break;
}
i++;
}
}
if(check==0)
{
printf("they are equal");
}
// else mai kuch likhne ki need nhi hai kyunki hum pehle hi print krva chuke hai strings are not
equal
return 0;
}
#include <stdio.h>
int main() {
// Write C code here
char str[100];
fgets(str,100,stdin);
int count=0;
int i=0;
while(str[i]!='\0')
{
i++;
}
char str1[i];
// printf("%i ",i);
for(int j=0; j<i;j++)
{
str1[j]=str[j];
// printf("%i ",j);
}
str1[i]='\0';
printf("%s ",str1);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
// Write C code here
char str[100];
fgets(str,100,stdin);
int *arr = calloc(200,sizeof(int));
int len=strlen(str);
for(int i=0; i<len;i++)
{
arr[str[i]]++;
}
// neeche ka code is same as findoig the largest number qno. 47
int li=0;
return 0;
}
70 -Write a program in C to find the number of times a given word 'the' appears in the given
string
71 - Write a program in C to Find the Frequency of Characters. take both as input (string)
as well as the char you want to find frequency of
#include <stdio.h>
int main() {
// Write C code here
char str[100];
fgets(str,100,stdin);
char ch;
scanf("%c",&ch);
int i=0;
int count=0;
while(str[i] != '\0')
{
if(str[i]==ch)
{
count++;
}
i++;
}
if(count ==0)
{
printf(" element sis not found");
}
else
{
printf("element occured %i times",count);
}
return 0;
}
#include <stdio.h>
int main() {
// Write C code here
char str[100];
fgets(str,100,stdin);
char str1[100];
fgets(str1,100,stdin);
int i=0;
while(str[i] != '\0')
{
i++;
}
int j=0;
while(str1[j] != '\0')
{
j++;
}
char str2[i+j-1];
int l=i+j-1;
// i-1 total charcter count of str
// j-1 total character count of str1
// str2 ki length honi chahiye i-1+j-1 + 1 extra 1 for \0
// str2=i-1+j-1+1= i+j-1
int m=0;
for(int k=0; k<i;k++)
{
str2[m]= str[k];
m++;
}
for(int k=0; k<j;k++)
{
str2[m]= str1[k];
m++;
}
str2[m]='\0';
printf("%s ",str2);
return 0;
}
#include <stdio.h>
int main() {
char str[100];
fgets(str,100,stdin);
char ch;
scanf("%c",&ch);
int i=0;
while(str[i]!='\0')
{
if(str[i]==' ')
{
str[i]=ch;
}
i++;
}
printf("%s",str);
return 0;
}
#include <stdio.h>
int main() {
char str[100];
fgets(str,100,stdin);
int i=0;
while(str[i]!='\0')
{ int j=i;
if(str[i]==' ')
{
while(str[j+1] !='\0')
{
str[j]=str[j+1];
j++;
}
}
i++;
}
printf("%s",str);
return 0;
}
otput - "apbqcrdset"
#include <stdio.h>
int main() {
char str[]="abcdef";
char str1[]="pqrst";
int i=0;
while(str[i] != '\0')
{
i++;
}
int j=0;
while(str1[j] != '\0')
{
j++;
}
char str2[i+j+1];
int l=i+j;
printf("%i",l);
// i total charcter count of str
// j total character count of str1
// str2 ki length honi chahiye i+j + 1 extra 1 for \0
// str2=i+j+1
int m=0;
for(int k=0; k<l;k+=2)
{
str2[k]= str[m];
// printf("%c",str[m]);
m++;
}
// printf("%s",str2);
m=0;
for(int k=1; k<l;k+=2)
{
str2[k]= str1[m];
m++;
}
str2[l]='\0';
printf("%s ",str2);
return 0;
}
______________________
MIXED QUESTIONS
______________________
78 - Write a C program to get the indices of the two numbers of a given array of integers,
such that the sum of the two numbers equal to a specific target.
Original Array: 4 2 1 5
Target Value: 7
Indices of the two numbers whose sum equal to target value: 7
13
_____________________
PATTERNS
_____________________
87 -
Right Triangle - Star
*
**
***
****
*****
#include <stdio.h>
int main() {
int n;
scanf("%i",&n);
for(int i=1; i<n;i++)
{
for(int j=1; j<=i;j++)
{
printf(" * ");
}
printf("\n");
}
return 0;
}
#include <stdio.h>
int main() {
int n;
scanf("%i",&n);
for(int i=1; i<n;i++)
{
for(int j=n-i; j>=1;j--)
{
printf(" * ");
}
printf("\n");
}
return 0;
}
#include <stdio.h>
int main()
{
int n;
scanf("%i",&n);
for(int i=1; i<n;i++)
{
for(int j=n-i; j>=1;j--)
{
printf(" ");
}
for(int k=1; k<=i;k++)
{
printf("* ");
}
printf("\n");
}
return 0;
}